Skip to content

Commit 2cc8b64

Browse files
add 1272
1 parent a268f4f commit 2cc8b64

File tree

7 files changed

+77
-5
lines changed

7 files changed

+77
-5
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,5 @@ LeetCode
573573
|1267|[Count Servers that Communicate](https://leetcode.com/problems/count-servers-that-communicate/)|c|[c++](./src/1267-Count-Servers-that-Communicate/1267.cpp)|[python](./src/1267-Count-Servers-that-Communicate/1267.py)|[go](./src/1267-Count-Servers-that-Communicate/1267.go)|[js](./src/1267-Count-Servers-that-Communicate/1267.js)|[java](./src/1267-Count-Servers-that-Communicate/1267.java)|Medium|
574574
|1268|[Search Suggestions System](https://leetcode.com/problems/search-suggestions-system/)|c|[c++](./src/1268-Search-Suggestions-System/1268.cpp)|[python](./src/1268-Search-Suggestions-System/1268.py)|[go](./src/1268-Search-Suggestions-System/1268.go)|[js](./src/1268-Search-Suggestions-System/1268.js)|[java](./src/1268-Search-Suggestions-System/1268.java)|Medium|
575575
|1269|[Number of Ways to Stay in the Same Place After Some Steps](https://leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps/)|c|[c++](./src/1269-Number-of-Ways-to-Stay-in-the-Same-Place-After-Some-Steps/1269.cpp)|[python](./src/1269-Number-of-Ways-to-Stay-in-the-Same-Place-After-Some-Steps/1269.py)|[go](./src/1269-Number-of-Ways-to-Stay-in-the-Same-Place-After-Some-Steps/1269.go)|[js](./src/1269-Number-of-Ways-to-Stay-in-the-Same-Place-After-Some-Steps/1269.js)|[java](./src/1269-Number-of-Ways-to-Stay-in-the-Same-Place-After-Some-Steps/1269.java)|Hard|
576-
|1271|[Hexspeak](https://leetcode.com/contest/biweekly-contest-14/problems/hexspeak/)|c|[c++](./src/1271-Hexspeak/1271.cpp)|[python](./src/1271-Hexspeak/1271.py)|[go](./src/1271-Hexspeak/1271.go)|[js](./src/1271-Hexspeak/1271.js)|[java](./src/1271-Hexspeak/1271.java)|Easy|
576+
|1271|[Hexspeak](https://leetcode.com/contest/biweekly-contest-14/problems/hexspeak/)|c|[c++](./src/1271-Hexspeak/1271.cpp)|[python](./src/1271-Hexspeak/1271.py)|[go](./src/1271-Hexspeak/1271.go)|[js](./src/1271-Hexspeak/1271.js)|[java](./src/1271-Hexspeak/1271.java)|Easy|
577+
|1272|[Remove Interval](https://leetcode.com/contest/biweekly-contest-14/problems/remove-interval/)|c|[c++](./src/1272-Remove-Interval/1272.cpp)|[python](./src/1272-Remove-Interval/1272.py)|[go](./src/1272-Remove-Interval/1272.go)|[js](./src/1272-Remove-Interval/1272.js)|[java](./src/1272-Remove-Interval/1272.java)|Medium|

src/1272-Remove-Interval/1272.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution
2+
{
3+
public:
4+
vector<vector<int>> removeInterval(vector<vector<int>>& intervals, vector<int>& toBeRemoved)
5+
{
6+
vector<vector<int>> res;
7+
for (auto& inter : intervals)
8+
{
9+
if (inter[0] >= toBeRemoved[1] || inter[1] <= toBeRemoved[0]) res.push_back(inter);
10+
else
11+
{
12+
if (inter[0] < toBeRemoved[0]) res.push_back({inter[0], toBeRemoved[0]});
13+
if (inter[1] > toBeRemoved[1]) res.push_back({toBeRemoved[1], inter[1]});
14+
}
15+
}
16+
return res;
17+
}
18+
};

src/1272-Remove-Interval/1272.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
func removeInterval(intervals [][]int, toBeRemoved []int) [][]int {
2+
res := make([][]int, 0)
3+
for _, inter := range intervals {
4+
if inter[0] >= toBeRemoved[1] || inter[1] <= toBeRemoved[0] {
5+
res = append(res, inter)
6+
} else {
7+
if inter[0] < toBeRemoved[0] {
8+
res = append(res, []int{inter[0], toBeRemoved[0]})
9+
}
10+
if inter[1] > toBeRemoved[1] {
11+
res = append(res, []int{toBeRemoved[1], inter[1]})
12+
}
13+
}
14+
}
15+
return res
16+
}

src/1272-Remove-Interval/1272.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public List<List<Integer>> removeInterval(int[][] intervals, int[] toBeRemoved) {
3+
List<List<Integer>> res = new ArrayList();
4+
for (int[] inter : intervals) {
5+
if (inter[1] <= toBeRemoved[0] || inter[0] >= toBeRemoved[1]) {
6+
res.add(Arrays.asList(inter[0], inter[1]));
7+
} else {
8+
if (inter[0] < toBeRemoved[0]) res.add(Arrays.asList(inter[0], toBeRemoved[0]));
9+
if (inter[1] > toBeRemoved[1]) res.add(Arrays.asList(toBeRemoved[1], inter[1]));
10+
}
11+
}
12+
return res;
13+
}
14+
}

src/1272-Remove-Interval/1272.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var removeInterval = function(intervals, toBeRemoved) {
2+
let res = [];
3+
for (let inter of intervals) {
4+
if (inter[0] >= toBeRemoved[1] || inter[1] <= toBeRemoved[0]) res.push(inter);
5+
else {
6+
if (inter[0] < toBeRemoved[0]) res.push([inter[0], toBeRemoved[0]]);
7+
if (inter[1] > toBeRemoved[1]) res.push([toBeRemoved[1], inter[1]]);
8+
}
9+
}
10+
return res;
11+
};

src/1272-Remove-Interval/1272.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[int]) -> List[List[int]]:
3+
res = []
4+
for i, j in intervals:
5+
if toBeRemoved[0] >= j or toBeRemoved[1] <= i:
6+
res.append([i, j])
7+
else:
8+
if toBeRemoved[0] > i:
9+
res.append([i, toBeRemoved[0]])
10+
if toBeRemoved[1] < j:
11+
res.append([toBeRemoved[1], j])
12+
return res

src/addProb.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import os, bisect
33

44
# 题目名称
5-
name = "Hexspeak"
6-
ID = 1271
7-
url = "https://leetcode.com/contest/biweekly-contest-14/problems/hexspeak/"
8-
difficult = "Easy"
5+
name = "Remove Interval"
6+
ID = 1272
7+
url = "https://leetcode.com/contest/biweekly-contest-14/problems/remove-interval/"
8+
difficult = "Medium"
99
prog = ['c', 'cpp', 'py', 'go', 'js', 'java']
1010

1111

0 commit comments

Comments
 (0)