Skip to content

Commit c8c27a9

Browse files
committed
Merge branch 'master' of https://github.com/doocs/leetcode.git
2 parents 6f53d54 + 4539f50 commit c8c27a9

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

solution/0055.Jump Game/Solution.java

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution {
2+
public boolean canJump(int[] nums) {
3+
int count=0;
4+
for(int i=nums.length-2;i>=0;i--) {
5+
if (nums[i] > count) count = 0;
6+
else count++;
7+
}
8+
return count==0;
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Definition for an interval.
3+
* public class Interval {
4+
* int start;
5+
* int end;
6+
* Interval() { start = 0; end = 0; }
7+
* Interval(int s, int e) { start = s; end = e; }
8+
* }
9+
*/
10+
class Solution {
11+
public List<Interval> merge(List<Interval> intervals) {
12+
int n=intervals.size();
13+
int[] starts=new int[n],ends=new int[n];
14+
for(int i=0;i<n;i++){
15+
starts[i]=intervals.get(i).start;
16+
ends[i]=intervals.get(i).end;
17+
}
18+
Arrays.sort(starts);
19+
Arrays.sort(ends);
20+
List<Interval> res= new ArrayList<>();
21+
for(int i=0,j=0;i<n;i++){
22+
if((i == (n - 1)) || (starts[i + 1] > ends[i])){
23+
res.add(new Interval(starts[j],ends[i]));
24+
j=i+1;
25+
}
26+
}
27+
return res;
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def setZeroes(self, matrix):
3+
"""
4+
:type matrix: List[List[int]]
5+
:rtype: void Do not return anything, modify matrix in-place instead.
6+
"""
7+
8+
coord = []
9+
for i in range(len(matrix)):
10+
for j in range(len(matrix[i])):
11+
if matrix[i][j] == 0:
12+
coord.append((i, j))
13+
14+
for i, j in coord:
15+
matrix[i] = [0]*len(matrix[i])
16+
for x in range(len(matrix)):
17+
matrix[x][j] = 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution:
2+
def searchMatrix(self, matrix, target):
3+
"""
4+
:type matrix: List[List[int]]
5+
:type target: int
6+
:rtype: bool
7+
"""
8+
9+
if not matrix or not matrix[0]:
10+
return False
11+
12+
for row in matrix:
13+
if row[0] <= target <= row[-1]:
14+
s = 0
15+
e = len(row)-1
16+
while s <= e:
17+
mid = (s+e)//2
18+
if row[mid] == target:
19+
return True
20+
elif row[mid] > target:
21+
e = mid-1
22+
else:
23+
s = mid+1
24+
25+
return False
26+
27+
return False

0 commit comments

Comments
 (0)