Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 combination-sum/sooooo-an.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function combinationSum(candidates: number[], target: number): number[][] {
const result: number[][] = [];

const dfs = (start: number, path: number[], sum: number) => {
if (sum === target) {
result.push([...path]);
return;
}

if (sum > target) {
return;
}

for (let i = start; i < candidates.length; i++) {
path.push(candidates[i]);
dfs(i, path, sum + candidates[i]);
path.pop();
}
};

dfs(0, [], 0);
return result;
}
15 changes: 15 additions & 0 deletions find-minimum-in-rotated-sorted-array/sooooo-an.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function findMin(nums: number[]): number {
let left = 0,
right = nums.length - 1;

while (left < right) {
const mid = left + Math.floor((right - left) / 2);
if (nums[mid] > nums[right]) {
left = mid + 1;
} else {
right = mid;
}
}

return nums[left];
}
6 changes: 6 additions & 0 deletions maximum-depth-of-binary-tree/sooooo-an.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function maxDepth(root: TreeNode | null): number {
if (!root) return 0;
const left = maxDepth(root.left);
const right = maxDepth(root.right);
return Math.max(left, right) + 1;
}
22 changes: 22 additions & 0 deletions merge-two-sorted-lists/sooooo-an.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function mergeTwoLists(
list1: ListNode | null,
list2: ListNode | null
): ListNode | null {
const result = new ListNode();
let tail = result;

while (list1 !== null && list2 !== null) {
if (list1.val <= list2.val) {
tail.next = list1;
list1 = list1.next;
} else {
tail.next = list2;
list2 = list2.next;
}
tail = tail.next;
}

tail.next = list1 !== null ? list1 : list2;

return result.next;
}