Skip to content

Commit 24e7352

Browse files
committed
新增別種解題方式。python oop 繼承、*args學習
1 parent a46aeb7 commit 24e7352

4 files changed

Lines changed: 15 additions & 0 deletions

File tree

javascript/LeetCode/Array/1588.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,17 @@ var sumOddLengthSubarrays = function (arr) {
6969
}
7070
}
7171
return count;
72+
73+
// solution 2.
74+
// let ans = 0;
75+
// for(let i = 0;i < arr.length;++i) {
76+
// let currentSum = 0;
77+
// for(let j = i;j < arr.length;++j) {
78+
// currentSum += arr[j];
79+
// ans += (j - i + 1) % 2 === 1 ? currentSum : 0;
80+
// }
81+
// }
82+
// return ans;
7283
};
7384
const arr = [1, 4, 2, 5, 3];
7485
console.log(sumOddLengthSubarrays(arr));

python/index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
greek.attack()
3333
greek.affend()
3434
print(greek.specice)
35+
print(greek.avgWeight(7,5))
3536

3637
# lion = Lion("獅子","未知","肉食")
3738
# lion.eat()

python/oop/Tortoise.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def environment(self):
3030
except NameError:
3131
print("eror")
3232

33+
def avgWeight(self,*args):
34+
return sum(args) / 2
35+
3336
# 繼承、覆寫
3437
def hibernation(self):
3538
return super().hibernation()
175 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)