diff --git a/71-80/74. Search a 2D Matrix.js b/71-80/74. Search a 2D Matrix.js new file mode 100644 index 0000000..f408c63 --- /dev/null +++ b/71-80/74. Search a 2D Matrix.js @@ -0,0 +1,13 @@ +var searchMatrix = function(matrix, target) { + for(let i = 0 ; i < matrix.length ; i++){ + if(target > matrix[i][matrix[0].length-1] ){ + continue + } + for(let j = 0 ; j < matrix[0].length ; j++){ + if(matrix[i][j] == target){ + return true + } + } + } + return false +}; \ No newline at end of file diff --git a/71-80/75. Sort Colors.js b/71-80/75. Sort Colors.js new file mode 100644 index 0000000..c2c57e9 --- /dev/null +++ b/71-80/75. Sort Colors.js @@ -0,0 +1,17 @@ +var sortColors = function(nums) { + let obj = {} + let l = nums.length + if(l == 1){return nums} + for(let i = 0 ; i < l ;i++){ + obj[nums[i]]= (obj[nums[i]])?obj[nums[i]]+1:1 + } + let j = 0 + for(let x in obj){ + while(obj[x] > 0){ + if(nums[j] < x){} + nums[j] = +x + obj[x]-- + j++ + } + } +}; \ No newline at end of file