classSolution: deftotalMoney(self, n: int) -> int: week, day = 1, 1 res = 0 for i inrange(n): res += week + day - 1 day += 1 if day == 8: day = 1 week += 1 return res
[sol1-Java]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
classSolution { publicinttotalMoney(int n) { intweek=1, day = 1; intres=0; for (inti=0; i < n; ++i) { res += week + day - 1; ++day; if (day == 8) { day = 1; ++week; } } return res; } }
[sol1-C#]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
publicclassSolution { publicintTotalMoney(int n) { int week = 1, day = 1; int res = 0; for (int i = 0; i < n; ++i) { res += week + day - 1; ++day; if (day == 8) { day = 1; ++week; } } return res; } }
[sol1-C++]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
classSolution { public: inttotalMoney(int n){ int week = 1, day = 1; int res = 0; for (int i = 0; i < n; ++i) { res += week + day - 1; ++day; if (day == 8) { day = 1; ++week; } } return res; } };
[sol1-C]
1 2 3 4 5 6 7 8 9 10 11 12 13
inttotalMoney(int n){ int week = 1, day = 1; int res = 0; for (int i = 0; i < n; ++i) { res += week + day - 1; ++day; if (day == 8) { day = 1; ++week; } } return res; }
[sol1-Golang]
1 2 3 4 5 6 7 8 9 10 11 12
functotalMoney(n int) (ans int) { week, day := 1, 1 for i := 0; i < n; i++ { ans += week + day - 1 day++ if day == 8 { day = 1 week++ } } return }
[sol1-JavaScript]
1 2 3 4 5 6 7 8 9 10 11 12 13
var totalMoney = function(n) { let week = 1, day = 1; let res = 0; for (let i = 0; i < n; ++i) { res += week + day - 1; ++day; if (day === 8) { day = 1; ++week; } } return res; };