Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ef76ee6

Browse filesBrowse files
committed
80th problem
1 parent 9fbab57 commit ef76ee6
Copy full SHA for ef76ee6

4 files changed

+71
-0
lines changed

‎71-80/77. Combinations.js

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var combine = function(n, k) {
2+
let result = []
3+
let traverse = (arr, depth) =>{
4+
if (arr.length === k) {
5+
result.push(arr)
6+
return
7+
}
8+
if (depth > n) {return}
9+
traverse(arr, depth + 1)
10+
traverse(arr.concat(depth), depth + 1)
11+
}
12+
traverse([], 1)
13+
return result;
14+
};

‎71-80/78. Subsets.js

Copy file name to clipboard
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var subsets = function(nums) {
2+
let ans = [[]]
3+
let k = []
4+
for(let i = 0 ; i < nums.length ; i++){
5+
let n = ans.length
6+
for(let j = 0 ; j < n ;j++){
7+
k = Array.from(ans[j])
8+
k.push(nums[i])
9+
ans.push(k)
10+
}
11+
}
12+
return ans
13+
};

‎71-80/79. Word Search.js

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var exist = function(board, word) {
2+
let found = false;
3+
const backtrack = (board, rIdx, cIdx, word, letterIdx) => {
4+
if(rIdx >= 0 && rIdx < board.length && cIdx >=0 && cIdx < board[0].length && board[rIdx][cIdx] === word[letterIdx]) {
5+
if(letterIdx === word.length-1) found ||= true;
6+
const curLetter = word[letterIdx];
7+
board[rIdx][cIdx] = '';
8+
backtrack(board, rIdx+1, cIdx, word, letterIdx+1);
9+
backtrack(board, rIdx-1, cIdx, word, letterIdx+1);
10+
backtrack(board, rIdx, cIdx+1, word, letterIdx+1);
11+
backtrack(board, rIdx, cIdx-1, word, letterIdx+1);
12+
board[rIdx][cIdx] = curLetter;
13+
}
14+
};
15+
16+
let letterIdx = 0;
17+
board.forEach((row, rIdx) => {
18+
row.forEach((cell, cIdx) => {
19+
if(cell === word[letterIdx]) {
20+
backtrack(board, rIdx, cIdx, word, letterIdx);
21+
if(found) return found;
22+
}
23+
})
24+
});
25+
return found;
26+
}
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
var removeDuplicates = function(nums) {
2+
let j = 0
3+
let [m,c,k] = [0,0,0]
4+
for(let i = 0 ; i <nums.length ;i++){
5+
k = nums[i]
6+
c = 0
7+
while(nums[i] == k){
8+
if(c < 2){
9+
nums[j++] = k
10+
c++
11+
m++
12+
}
13+
i++
14+
}
15+
i--
16+
}
17+
nums.length = m
18+
};

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.