Skip to content

Commit 782e347

Browse files
committed
feat: add solutions to lc problem: No.2580
No.2580.Count Ways to Group Overlapping Ranges
1 parent 9cd7de6 commit 782e347

File tree

6 files changed

+57
-8
lines changed

6 files changed

+57
-8
lines changed

solution/2500-2599/2580.Count Ways to Group Overlapping Ranges/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,24 @@ func countWays(ranges [][]int) int {
251251
}
252252
```
253253

254+
### **TypeScript**
255+
256+
```ts
257+
function countWays(ranges: number[][]): number {
258+
ranges.sort((a, b) => a[0] - b[0]);
259+
let mx = -1;
260+
let ans = 1;
261+
const mod = 10 ** 9 + 7;
262+
for (const [start, end] of ranges) {
263+
if (start > mx) {
264+
ans = (ans * 2) % mod;
265+
}
266+
mx = Math.max(mx, end);
267+
}
268+
return ans;
269+
}
270+
```
271+
254272
### **...**
255273

256274
```

solution/2500-2599/2580.Count Ways to Group Overlapping Ranges/README_EN.md

+18
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,24 @@ func countWays(ranges [][]int) int {
233233
}
234234
```
235235

236+
### **TypeScript**
237+
238+
```ts
239+
function countWays(ranges: number[][]): number {
240+
ranges.sort((a, b) => a[0] - b[0]);
241+
let mx = -1;
242+
let ans = 1;
243+
const mod = 10 ** 9 + 7;
244+
for (const [start, end] of ranges) {
245+
if (start > mx) {
246+
ans = (ans * 2) % mod;
247+
}
248+
mx = Math.max(mx, end);
249+
}
250+
return ans;
251+
}
252+
```
253+
236254
### **...**
237255

238256
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function countWays(ranges: number[][]): number {
2+
ranges.sort((a, b) => a[0] - b[0]);
3+
let mx = -1;
4+
let ans = 1;
5+
const mod = 10 ** 9 + 7;
6+
for (const [start, end] of ranges) {
7+
if (start > mx) {
8+
ans = (ans * 2) % mod;
9+
}
10+
mx = Math.max(mx, end);
11+
}
12+
return ans;
13+
}

solution/CONTEST_README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
| 段位 | 比例 | 段位名 | 国服分数线 | 勋章 |
1313
| ----- | ------ | -------- | --------- | --------------------------------------------------------------------------- |
14-
| LV3 | 5% | Guardian | &ge;2265.64 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Guardian.gif" style="width: 80px;" /></p> |
15-
| LV2 | 20% | Knight | &ge;1894.28 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Knight.gif" style="width: 80px;" /></p> |
14+
| LV3 | 5% | Guardian | &ge;2251.88 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Guardian.gif" style="width: 80px;" /></p> |
15+
| LV2 | 20% | Knight | &ge;1879.80 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Knight.gif" style="width: 80px;" /></p> |
1616
| LV1 | 75% | - | - | - |
1717

1818
力扣竞赛 **全国排名前 10** 的用户,全站用户名展示为品牌橙色。

solution/contest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ def generate_contest_list():
127127
128128
| 段位 | 比例 | 段位名 | 国服分数线 | 勋章 |
129129
| ----- | ------ | -------- | --------- | --------------------------------------------------------------------------- |
130-
| LV3 | 5% | Guardian | &ge;2265.64 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Guardian.gif" style="width: 80px;" /></p> |
131-
| LV2 | 20% | Knight | &ge;1894.28 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Knight.gif" style="width: 80px;" /></p> |
130+
| LV3 | 5% | Guardian | &ge;2251.88 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Guardian.gif" style="width: 80px;" /></p> |
131+
| LV2 | 20% | Knight | &ge;1879.80 | <p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/images/Knight.gif" style="width: 80px;" /></p> |
132132
| LV1 | 75% | - | - | - |
133133
134134
力扣竞赛 **全国排名前 10** 的用户,全站用户名展示为品牌橙色。

solution/rating.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def get_user_ranking(self, uid):
104104
return None
105105

106106
def get_1600_count(self):
107-
left, right = 1, 1000 if self.region == 'CN' else 3000
107+
left, right = 1, 4000
108108
while left < right:
109109
mid = (left + right + 1) >> 1
110110
page = self.load_page(mid)
@@ -116,17 +116,17 @@ def get_1600_count(self):
116116
left = mid
117117
else:
118118
right = mid - 1
119-
page = self.load_page(left)
119+
page = [uid for _, uid in self.load_page(left) if uid]
120120
print('校准中...')
121121
left, right = 0, len(page) - 1
122122
while left < right:
123123
mid = (left + right + 1) >> 1
124-
ranking, score = self.get_user_ranking(page[mid][1])
124+
ranking, score = self.get_user_ranking(page[mid])
125125
if score >= 1600:
126126
left = mid
127127
else:
128128
right = mid - 1
129-
return self.get_user_ranking(page[left][1])[0]
129+
return self.get_user_ranking(page[left])[0]
130130

131131
def get_user(self, rank):
132132
p = (rank - 1) // 25 + 1

0 commit comments

Comments
 (0)