Skip to content

Commit d03288b

Browse files
committed
add 3038 fot JS and Python
1 parent a8ba9df commit d03288b

5 files changed

Lines changed: 50 additions & 6 deletions

File tree

javascript/LeetCode/Array/3038.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 3038. Maximum Number of Operations With the Same Score I
3+
*
4+
* 以陣列前兩個元素為一組做加總為一步驟,檢查下一組的加總是否跟前一組一樣,若不是,則回傳結果是一樣的步驟有幾個
5+
* 要能夠取得連續加總值一樣
6+
*
7+
* @param {number[]} nums
8+
* @return {number}
9+
*/
10+
var maxOperations = function(nums) {
11+
let count = 1;
12+
let firstTwoEleSum = nums[0] + nums[1];
13+
for(let i = 2;i < nums.length - 1;i+=2) {
14+
if(nums[i] + nums[i+1] === firstTwoEleSum){
15+
count++;
16+
}else{
17+
break;
18+
}
19+
}
20+
return count;
21+
};
22+
let nums = [1,5,3,3,4,1,3,2,2,3];
23+
// 2
24+
console.log(maxOperations(nums));

python/index.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
# oop
2323
# from file name(module) import the class.
24-
# from oop.Animal import Animal
25-
# from oop.Tortoise import Tortoise
26-
# from oop.Lion import Lion
27-
# from oop.Behavior import move
24+
from oop.Animal import Animal
25+
from oop.Tortoise import Tortoise
26+
from oop.Lion import Lion
27+
from oop.Behavior import move
2828

29-
# greek = Tortoise("福氣",7,"veggie","地中海型陸龜")
30-
# greek.eat()
29+
greek = Tortoise("福氣",7,"veggie","地中海型陸龜")
30+
greek.eat()
3131
# greek.hibernation()
3232
# greek.environment()
3333
# greek.attack()

python/leetcode/list/3038.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from typing import List
2+
def maxOperations(nums: List[int]) -> int:
3+
'''
4+
3038. Maximum Number of Operations With the Same Score I
5+
'''
6+
count = 1
7+
firstTwoEleSum = nums[0] + nums[1]
8+
for i in range(2,len(nums) - 1,2):
9+
if nums[i] + nums[i+1] == firstTwoEleSum:
10+
count+=1
11+
else:
12+
break
13+
return count
14+
15+
nums = [3,2,1,4,5]
16+
print(maxOperations(nums))

python/oop/Tortoise.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def __init__(self, name, age, food,speciceType:str):
1212
super().__init__(name, age, food)
1313
self.speciceType = speciceType
1414

15+
def eat(self):
16+
cant = ["草酸高食物","糖份高,例如水果"]
17+
18+
print(f"{self.food},但有些不適合吃")
1519

1620
def environment(self):
1721
'''
209 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)