8000 73rd problem · Tahirc1/LeetcodeJs@9fbab57 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9fbab57

Browse files
committed
73rd problem
1 parent c79ba7c commit 9fbab57

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

71-80/74. Search a 2D Matrix.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var searchMatrix = function(matrix, target) {
2+
for(let i = 0 ; i < matrix.length ; i++){
3+
if(target > matrix[i][matrix[0].length-1] ){
4+
continue
5+
}
6+
for(let j = 0 ; j < matrix[0].length ; j++){
7+
if(matrix[i][j] == target){
8+
return true
9+
}
10+
}
11+
}
12+
return false
13+
};

71-80/75. Sort Colors.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var sortColors = function(nums) {
2+
let obj = {}
3+
let l = nums.length
4+
if(l == 1){return nums}
5+
for(let i = 0 ; i < l ;i++){
6+
obj[nums[i]]= (obj[nums[i]])?obj[nums[i]]+1:1
7+
}
8+
let j = 0
9+
for(let x in obj){
10+
while(obj[x] > 0){
11+
if(nums[j] < x){}
12+
nums[j] = +x
13+
obj[x]--
14+
j++
15+
}
16+
}
17+
};

0 commit comments

Comments
 (0)
0