Skip to content

Commit

Permalink
Merge pull request #886 from Seungyeon0321/main
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Nov 13, 2023
2 parents 852a832 + 1faca60 commit db89020
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 0 deletions.
2 changes: 2 additions & 0 deletions SeungyeonJi/week7/2023-10-29-SumRootToLeafNumbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ var sumNumbers = function (root) {

return num;
};


File renamed without changes.
Empty file.
11 changes: 11 additions & 0 deletions SeungyeonJi/week8/2023-11-05.MaximumSubarrayjs
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 SeungyeonJi/week9/2023-11-10-LetterCombinationsOfAPhoneNumber.js
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;
};
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;
};
36 changes: 36 additions & 0 deletions SeungyeonJi/week9/2023-11-12-WordSearch.js
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;
};

0 comments on commit db89020

Please sign in to comment.