Skip to content

Commit 8cc6f95

Browse files
committed
feat: update python solutions to lc problems
1 parent fe9e415 commit 8cc6f95

File tree

18 files changed

+132
-83
lines changed

18 files changed

+132
-83
lines changed

solution/0800-0899/0852.Peak Index in a Mountain Array/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,24 @@ var peakIndexInMountainArray = function (arr) {
174174
};
175175
```
176176

177+
### **TypeScript**
178+
179+
```ts
180+
function peakIndexInMountainArray(arr: number[]): number {
181+
let left = 1,
182+
right = arr.length - 2;
183+
while (left < right) {
184+
const mid = (left + right) >> 1;
185+
if (arr[mid] > arr[mid + 1]) {
186+
right = mid;
187+
} else {
188+
left = mid + 1;
189+
}
190+
}
191+
return left;
192+
}
193+
```
194+
177195
### **...**
178196

179197
```

solution/0800-0899/0852.Peak Index in a Mountain Array/README_EN.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,24 @@ var peakIndexInMountainArray = function (arr) {
149149
};
150150
```
151151

152+
### **TypeScript**
153+
154+
```ts
155+
function peakIndexInMountainArray(arr: number[]): number {
156+
let left = 1,
157+
right = arr.length - 2;
158+
while (left < right) {
159+
const mid = (left + right) >> 1;
160+
if (arr[mid] > arr[mid + 1]) {
161+
right = mid;
162+
} else {
163+
left = mid + 1;
164+
}
165+
}
166+
return left;
167+
}
168+
```
169+
152170
### **...**
153171

154172
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function peakIndexInMountainArray(arr: number[]): number {
2+
let left = 1,
3+
right = arr.length - 2;
4+
while (left < right) {
5+
const mid = (left + right) >> 1;
6+
if (arr[mid] > arr[mid + 1]) {
7+
right = mid;
8+
} else {
9+
left = mid + 1;
10+
}
11+
}
12+
return left;
13+
}

solution/0900-0999/0981.Time Based Key-Value Store/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class TimeMap:
8383
return ''
8484
tv = self.ktv[key]
8585
# #查找第一个大于timestamp的
86-
i = bisect.bisect_right(tv, (timestamp, chr(127)))
86+
i = bisect_right(tv, (timestamp, chr(127)))
8787
return tv[i - 1][1] if i else ''
8888

8989

solution/0900-0999/0981.Time Based Key-Value Store/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class TimeMap:
6767
if key not in self.ktv:
6868
return ''
6969
tv = self.ktv[key]
70-
i = bisect.bisect_right(tv, (timestamp, chr(127)))
70+
i = bisect_right(tv, (timestamp, chr(127)))
7171
return tv[i - 1][1] if i else ''
7272

7373

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
class TimeMap:
2-
def __init__(self):
3-
"""
4-
Initialize your data structure here.
5-
"""
6-
self.ktv = defaultdict(list)
7-
8-
def set(self, key: str, value: str, timestamp: int) -> None:
9-
self.ktv[key].append((timestamp, value))
10-
11-
def get(self, key: str, timestamp: int) -> str:
12-
if key not in self.ktv:
13-
return ''
14-
tv = self.ktv[key]
15-
i = bisect.bisect_right(tv, (timestamp, chr(127)))
16-
return tv[i - 1][1] if i else ''
17-
18-
19-
# Your TimeMap object will be instantiated and called as such:
20-
# obj = TimeMap()
21-
# obj.set(key,value,timestamp)
22-
# param_2 = obj.get(key,timestamp)
1+
class TimeMap:
2+
def __init__(self):
3+
"""
4+
Initialize your data structure here.
5+
"""
6+
self.ktv = defaultdict(list)
7+
8+
def set(self, key: str, value: str, timestamp: int) -> None:
9+
self.ktv[key].append((timestamp, value))
10+
11+
def get(self, key: str, timestamp: int) -> str:
12+
if key not in self.ktv:
13+
return ''
14+
tv = self.ktv[key]
15+
i = bisect_right(tv, (timestamp, chr(127)))
16+
return tv[i - 1][1] if i else ''
17+
18+
19+
# Your TimeMap object will be instantiated and called as such:
20+
# obj = TimeMap()
21+
# obj.set(key,value,timestamp)
22+
# param_2 = obj.get(key,timestamp)

solution/1100-1199/1150.Check If a Number Is Majority Element in a Sorted Array/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Solution:
9292
```python
9393
class Solution:
9494
def isMajorityElement(self, nums: List[int], target: int) -> bool:
95-
left, right = bisect.bisect_left(nums, target), bisect.bisect_right(nums, target)
95+
left, right = bisect_left(nums, target), bisect_right(nums, target)
9696
return right - left > (len(nums) >> 1)
9797
```
9898

solution/1100-1199/1150.Check If a Number Is Majority Element in a Sorted Array/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Solution:
7676
```python
7777
class Solution:
7878
def isMajorityElement(self, nums: List[int], target: int) -> bool:
79-
left, right = bisect.bisect_left(nums, target), bisect.bisect_right(nums, target)
79+
left, right = bisect_left(nums, target), bisect_right(nums, target)
8080
return right - left > (len(nums) >> 1)
8181
```
8282

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
class Solution:
2-
def isMajorityElement(self, nums: List[int], target: int) -> bool:
3-
left, right = bisect.bisect_left(nums, target), bisect.bisect_right(
4-
nums, target
5-
)
6-
return right - left > (len(nums) >> 1)
1+
class Solution:
2+
def isMajorityElement(self, nums: List[int], target: int) -> bool:
3+
left, right = bisect_left(nums, target), bisect_right(
4+
nums, target
5+
)
6+
return right - left > (len(nums) >> 1)

solution/1800-1899/1889.Minimum Space Wasted From Packaging/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Solution:
8585
continue
8686
t = last = 0
8787
for b in box:
88-
idx = bisect.bisect_right(packages, b, lo=last)
88+
idx = bisect_right(packages, b, lo=last)
8989
t += (idx - last) * b
9090
last = idx
9191
res = min(res, t)

0 commit comments

Comments
 (0)