Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
22af45a
15 / 3Sum / Medium / 45m
CitrusSoda Sep 24, 2024
4f06365
217 / Contains Duplicate / Easy / 5m
CitrusSoda Sep 24, 2024
a0046a2
268 / Missing Number / Easy / 5m
CitrusSoda Sep 24, 2024
a43236c
121 / Best Time to Buy and Sell Stock / Easy / 30m
CitrusSoda Sep 24, 2024
cf51996
? / Meeting Schedule / Easy / 10m
CitrusSoda Sep 24, 2024
56edc58
242 / Valid Anagram / Easy / 9m 56s
CitrusSoda Oct 2, 2024
d4aabdb
238 / Product of Array Except Self / Medium / 26m 33s
CitrusSoda Oct 2, 2024
93e01a5
191 / Number of 1 Bits / Easy / 9m 27s
CitrusSoda Oct 2, 2024
95e3024
100 / Same Tree / Easy / 15m 52s
CitrusSoda Oct 2, 2024
ee3e845
746 / Min Cost Climbing Stairs / Easy / 22m 30s
CitrusSoda Oct 2, 2024
0f0614c
49 / Group Anagrams / Medium / x.. (O(n^2) 26m 46s)
CitrusSoda Oct 8, 2024
c00cd47
190 / Reverse Bits / Easy / 9m 36s
CitrusSoda Oct 8, 2024
7b9ca52
125 / Valid Palindrome / Easy / 9m 36s
CitrusSoda Oct 8, 2024
d2e3330
322 / Coin Change / Medium / 19m 32s
CitrusSoda Oct 8, 2024
a4b0114
206 / Reverse Linked List / Easy / 4m 52s
CitrusSoda Oct 8, 2024
6c19337
1 / Two Sum / Easy / 7m 05s
CitrusSoda Oct 15, 2024
7101916
104 / Maximum Depth of Binary Tree / Easy / 6m 20s
CitrusSoda Oct 15, 2024
5b5197d
141 / Linked List Cycle / Easy / X
CitrusSoda Oct 15, 2024
2fc582c
202 / Happy Number / Easy / 7m 33s
CitrusSoda Oct 15, 2024
0d4e8a1
20 / Valid Parentheses / Easy / 16m 30s
CitrusSoda Oct 15, 2024
f497d1c
4 week / cpp
CitrusSoda Oct 16, 2024
c97a60b
338 / Counting Bits / Easy / 4m 22s
CitrusSoda Oct 22, 2024
1eb6cdb
70 / Climbing Stairs / Easy / 1m 41s
CitrusSoda Oct 22, 2024
ce9edc9
21 / Merge TWo Sorted Lists / Easy / 21m 43s
CitrusSoda Oct 22, 2024
8203dfd
48 / Rotate Image / Medium / 12m 51s
CitrusSoda Oct 22, 2024
ac16c0f
1046 / Last Stone Weight / Easy / 6m 51s
CitrusSoda Oct 22, 2024
47c9ab7
659 / Encode And Decode Strings / Medium / x
CitrusSoda Oct 29, 2024
6e1e922
198 / House Robber / Medium / 12m 19s
CitrusSoda Oct 29, 2024
18c7ec1
66 / Plus One / Easy / 9m 32s
CitrusSoda Oct 29, 2024
41415b0
704 / Binary Search / Easy / 14m 52s
CitrusSoda Oct 29, 2024
d3080fb
703 / Kth Largest Element in a Stream / Easy / >20
CitrusSoda Oct 29, 2024
92d8e1e
136 / Single Number / Easy / 4m 46s
CitrusSoda Nov 5, 2024
f766a03
110 / Balanced Binary Tree / Easy / 27m 37s
CitrusSoda Nov 5, 2024
7796678
54 / Spiral Matrix / Medium / 19m 15s
CitrusSoda Nov 5, 2024
8bbac88
155 / Min Stack / Medium / 11m 12s
CitrusSoda Nov 5, 2024
62545b2
973 / K Closest Points To Origin / Medium / 16m 22s
CitrusSoda Nov 5, 2024
33b0873
128 / Longest Consecutive Sequence / Medium / >30m
CitrusSoda Nov 12, 2024
713287d
371 / Sum of Two Integers / Medium / 23m 16s
CitrusSoda Nov 12, 2024
af5bd0d
543 / Diameter of Binary Tree / Easy / 13m 12s
CitrusSoda Nov 12, 2024
f048a03
226 / Invert Binary Tree / Easy / 7m 42s
CitrusSoda Nov 12, 2024
0b703b1
208 / Implement Trie / Medium / >30m
CitrusSoda Nov 12, 2024
02b6924
102 / Binary Tree Level Order Traversal / Medium / 21m 43s
CitrusSoda Nov 19, 2024
7ff9a52
572 / Subtree Of Another Tree / Easy / 18m 41s
CitrusSoda Nov 19, 2024
31927b3
213 / House Robber II / Medium / 21m 03s
CitrusSoda Nov 19, 2024
8b67876
150 / Evaluate Reverse Polish Notation / Medium / 12m 36s
CitrusSoda Nov 19, 2024
7447e8b
207 / Course Scheduel / Medium / >30m
CitrusSoda Nov 19, 2024
980901e
56 / Merge Intervals / Medium / 22m 31s
CitrusSoda Nov 26, 2024
d720682
1584 / Min Cost to Connect All Points / Medium / >25m
CitrusSoda Nov 26, 2024
4188bba
235 / Lowest Common Ancestor of a Binary Search Tree / Medium / 13m 12s
CitrusSoda Nov 26, 2024
5056d9a
139 / Word Break / Medium / 23m 19s
CitrusSoda Nov 26, 2024
2f32e8e
215 / Kth Largest Element in an Array / Medium / 2m
CitrusSoda Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions citrussoda/10week/139_word-break.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @param {string} s
* @param {string[]} wordDict
* @return {boolean}
*/
var wordBreak = function (s, wordDict) {
const dp = new Array(s.length + 1).fill(false);
dp[0] = true;

for (let i = 1; i <= s.length; i++) {
for (let word of wordDict) {
if (i >= word.length && dp[i - word.length]) {
const sub = s.slice(i - word.length, i);
if (sub === word) {
dp[i] = true;
break;
}
}
}
}

return dp[s.length];
};
45 changes: 45 additions & 0 deletions citrussoda/10week/1584_min-cost-to-connect-all-points.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @param {number[][]} points
* @return {number}
*/
// Prim's Algorithm
var minCostConnectPoints = function (points) {
const n = points.length;

// ๋ฐฉ๋ฌธ ์—ฌ๋ถ€๋ฅผ ์ฒดํฌํ•˜๋Š” ๋ฐฐ์—ด
const visited = new Set();

// ๊ฐ ์ ๊นŒ์ง€์˜ ์ตœ์†Œ ๊ฑฐ๋ฆฌ๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐฐ์—ด
const distances = new Array(n).fill(Infinity);
distances[0] = 0;

let totalCost = 0;

for (let i = 0; i < n; i++) {
let minDist = Infinity;
let minIndex = -1;

// ์•„์ง ๋ฐฉ๋ฌธํ•˜์ง€ ์•Š์€ ์ ๋“ค ์ค‘์—์„œ ์ตœ์†Œ ๊ฑฐ๋ฆฌ๋ฅผ ๊ฐ€์ง„ ์ ์„ ์ฐพ์Œ
for (let j = 0; j < n; j++) {
if (!visited.has(j) && distances[j] < minDist) {
minDist = distances[j];
minIndex = j;
}
}

visited.add(minIndex);
totalCost += minDist;

// ์„ ํƒ๋œ ์ ์—์„œ ๋‹ค๋ฅธ ๋ชจ๋“  ์ ๊นŒ์ง€์˜ ๊ฑฐ๋ฆฌ๋ฅผ ์—…๋ฐ์ดํŠธ
for (let j = 0; j < n; j++) {
if (!visited.has(j)) {
const distance =
Math.abs(points[minIndex][0] - points[j][0]) +
Math.abs(points[minIndex][1] - points[j][1]);
distances[j] = Math.min(distances[j], distance);
}
}
}

return totalCost;
};
10 changes: 10 additions & 0 deletions citrussoda/10week/215_kth-largest-element-in-an-array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @param {number[]} nums
* @param {number} k
* @return {number}
*/
var findKthLargest = function (nums, k) {
nums.sort((a, b) => b - a);

return nums[k - 1];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/

/**
* @param {TreeNode} root
* @param {TreeNode} p
* @param {TreeNode} q
* @return {TreeNode}
*/
var lowestCommonAncestor = function (root, p, q) {
if (root.val > p.val && root.val < q.val) {
return root;
}

if (root.val > p.val && root.val > q.val) {
return lowestCommonAncestor(root.left, p, q);
}

if (root.val < p.val && root.val < q.val) {
return lowestCommonAncestor(root.right, p, q);
}

return root;
};
24 changes: 24 additions & 0 deletions citrussoda/10week/56_merge-intervals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @param {number[][]} intervals
* @return {number[][]}
*/
var merge = function (intervals) {
intervals.sort((a, b) => a[0] - b[0]);

const ans = [];
let prev = intervals[0];

for (let i = 1; i < intervals.length; i++) {
let interval = intervals[i];

if (interval[0] <= prev[1]) {
prev[1] = Math.max(prev[1], interval[1]);
} else {
ans.push(prev);
prev = interval;
}
}

ans.push(prev);
return ans;
};
15 changes: 15 additions & 0 deletions citrussoda/1week/121.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @param {number[]} prices
* @return {number}
*/
var maxProfit = function (prices) {
let maxCurrent = 0;
let maxSoFar = 0;

for (let i = 1; i < prices.length; i++) {
maxCurrent = Math.max(0, maxCurrent + prices[i] - prices[i - 1]);
maxSoFar = Math.max(maxSoFar, maxCurrent);
}

return maxSoFar;
};
42 changes: 42 additions & 0 deletions citrussoda/1week/15.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @param {number[]} nums
* @return {number[][]}
*/
var threeSum = function (nums) {
let answer = [];

nums.sort((a, b) => a - b);

for (let i = 0; i < nums.length - 2; i++) {
if (nums[i] === nums[i - 1]) continue;

let target = nums[i];
let startIndex = i + 1;
let lastIndex = nums.length - 1;

while (startIndex < lastIndex) {
let sum = target + nums[startIndex] + nums[lastIndex];
if (sum > 0) {
lastIndex -= 1;
} else if (sum < 0) {
startIndex += 1;
} else {
answer.push([target, nums[startIndex], nums[lastIndex]]);
while (
startIndex < lastIndex &&
nums[startIndex] === nums[startIndex + 1]
)
startIndex += 1;
while (
startIndex < lastIndex &&
nums[lastIndex] === nums[lastIndex - 1]
)
lastIndex -= 1;
startIndex += 1;
lastIndex -= 1;
}
}
}

return answer;
};
9 changes: 9 additions & 0 deletions citrussoda/1week/217.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function (nums) {
const setNums = new Set(nums);

return setNums.size !== nums.length;
};
11 changes: 11 additions & 0 deletions citrussoda/1week/268.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @param {number[]} nums
* @return {number}
*/
var missingNumber = function (nums) {
nums.sort((a, b) => a - b);

for (let i = 0; i <= nums.length; i++) {
if (nums[i] !== i) return i;
}
};
27 changes: 27 additions & 0 deletions citrussoda/1week/meetingSchedule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Definition of Interval:
* class Interval {
* constructor(start, end) {
* this.start = start;
* this.end = end;
* }
* }
*/

class Solution {
/**
* @param {Interval[]} intervals
* @returns {boolean}
*/
canAttendMeetings(intervals) {
intervals.sort((a, b) => a.start - b.start);

for (let i = 1; i < intervals.length; i++) {
if (intervals[i - 1].end > intervals[i].start) {
return false;
}
}

return true;
}
}
48 changes: 48 additions & 0 deletions citrussoda/2week/100_same-tree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} p
* @param {TreeNode} q
* @return {boolean}
*/
var isSameTree = function (p, q) {
let firstTree = [];
let secondTree = [];

iter(p, firstTree);
iter(q, secondTree);

if (firstTree.length !== secondTree.length) return false;

for (let i = 0; i < firstTree.length - 1; i++) {
if (firstTree[i] !== secondTree[i]) return false;
}

return true;
};

const iter = (target, tree) => {
if (!target) return tree;

tree.push(target.val);

if (target.left) {
iter(target.left, tree);
} else if (target.left === null) {
tree.push(null);
}

if (target.right) {
iter(target.right, tree);
} else if (target.right === null) {
tree.push(null);
}

return tree;
};
19 changes: 19 additions & 0 deletions citrussoda/2week/191_number-of-1-bits.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @param {number} n
* @return {number}
*/
var hammingWeight = function (n) {
return findBit(n, 0);
};

const findBit = (n, count) => {
if (n < 1) return count;

let i = 1;
while (i <= n / 2) {
i *= 2;
}
count++;

return findBit(n - i, count);
};
23 changes: 23 additions & 0 deletions citrussoda/2week/238_product-of-array-except-self.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @param {number[]} nums
* @return {number[]}
*/
var productExceptSelf = function (nums) {
let answer = Array.from({ length: nums.length }).fill(1);

let left = 1;

for (let i = 0; i < nums.length; i++) {
answer[i] *= left;
left *= nums[i];
}

let right = 1;

for (let i = nums.length - 1; i >= 0; i--) {
answer[i] *= right;
right *= nums[i];
}

return answer;
};
22 changes: 22 additions & 0 deletions citrussoda/2week/242_valid-anagram.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
var isAnagram = function (s, t) {
if (s.length !== t.length) return false;

let firstStr = {};
[...s].forEach((char) => (firstStr[char] = (firstStr[char] || 0) + 1));

let secondStr = {};
[...t].forEach((char) => (secondStr[char] = (secondStr[char] || 0) + 1));

for (let char in firstStr) {
if (firstStr[char] !== secondStr[char]) {
return false;
}
}

return true;
};
15 changes: 15 additions & 0 deletions citrussoda/2week/746_min-cost-climbing-stairs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @param {number[]} cost
* @return {number}
*/
var minCostClimbingStairs = function (cost) {
let dp = Array.from({ length: cost.length + 1 }, () => 0);

for (let i = 2; i <= cost.length; i++) {
dp[i] = Math.min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2]);
}

console.log(dp);

return dp[dp.length - 1];
};
Loading
Loading