-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #886 from Seungyeon0321/main
- Loading branch information
Showing
7 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,5 @@ var sumNumbers = function (root) { | |
|
||
return num; | ||
}; | ||
|
||
|
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
var maxSubArray = function (nums) { | ||
let maxSum = nums[0]; | ||
let currentSum = nums[0]; | ||
|
||
for (let i = 0; i < nums.length; i++) { | ||
currentSum = Math.max(num[i], currentSum + num[i]); | ||
maxSum = Math.max(maxSum, currentSum); | ||
} | ||
|
||
return maxSum; | ||
}; |
38 changes: 38 additions & 0 deletions
38
SeungyeonJi/week9/2023-11-10-LetterCombinationsOfAPhoneNumber.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
let letterCombinations = function (digits) { | ||
let result = []; | ||
|
||
//alpha has map | ||
const alpha = { | ||
2: "abc", | ||
3: "def", | ||
4: "ghi", | ||
5: "jkl", | ||
6: "mno", | ||
7: "pqrs", | ||
8: "tuv", | ||
9: "wxyz", | ||
}; | ||
|
||
const dfs = function (i, digits, state) { | ||
// base case (condition to sotp this recursive function) | ||
|
||
// If we loop through digits.length time, we will return the result; | ||
if (i === digits.length) { | ||
result.push(slate.join("")); | ||
return; | ||
} | ||
|
||
//dfs recursive case | ||
let chars = alpha[digits[i]]; | ||
|
||
for (let char of chars) { | ||
state.push(char); | ||
dfs(i + 1, digits, state); | ||
state.pop(); | ||
} | ||
}; | ||
|
||
dfs(0, digits, []); | ||
|
||
return result; | ||
}; |
24 changes: 24 additions & 0 deletions
24
SeungyeonJi/week9/2023-11-12-SplitAStringIntoTheMaxNumberOfUniqueSubstrings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var maxUniqueSplit = function (s) { | ||
let wordSet = new Set(), | ||
res = 1; | ||
|
||
function checkUniqueSubstring(i) { | ||
if (i === s.length) { | ||
res = Math.max(wordSet.size, res); | ||
return; | ||
} | ||
|
||
for (let j = i + 1; j <= s.length; j++) { | ||
let str = s.substring(i, j); | ||
if (!wordSet.has(str)) { | ||
wordSet.add(str); | ||
checkUniqueSubstring(j); | ||
wordSet.delete(str); | ||
} | ||
} | ||
} | ||
|
||
checkUniqueSubstring(0); | ||
|
||
return res; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const isOutOfBound = (board, row, col) => | ||
row < 0 || row >= board.length || col < 0 || col >= board[0].length; | ||
|
||
const checkNeighbors = (board, word, row, col) => { | ||
// Check exit conditions | ||
if (!word.length) return true; | ||
if (isOutOfBound(board, row, col) || board[row][col] !== word[0]) | ||
return false; | ||
|
||
// Save some stuff | ||
const curChar = board[row][col]; | ||
const newWord = word.substr(1); | ||
|
||
board[row][col] = 0; // Disable the current character | ||
|
||
// Check if neighbors are fruitful | ||
const results = | ||
checkNeighbors(board, newWord, row + 1, col) || | ||
checkNeighbors(board, newWord, row - 1, col) || | ||
checkNeighbors(board, newWord, row, col + 1) || | ||
checkNeighbors(board, newWord, row, col - 1); | ||
|
||
// Enable current character | ||
board[row][col] = curChar; | ||
|
||
return results; | ||
}; | ||
|
||
var exist = function (board, word) { | ||
for (let row = 0; row < board.length; row++) { | ||
for (let col = 0; col < board[0].length; col++) { | ||
if (checkNeighbors(board, word, row, col)) return true; | ||
} | ||
} | ||
return false; | ||
}; |