This file contains hidden or 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
import { | |
BrowserRouter, | |
Navigate, | |
useNavigate, | |
useRoutes, | |
} from "react-router-dom"; | |
import { ErrorBoundary } from "src/components/ErrorBoundary"; | |
import { PageLayout } from "src/components/pageLayout/pageLayout"; | |
import { | |
BooksContextProvider, |
This file contains hidden or 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
function permute(word, pattern, permutations = []) { | |
if(word.length === 0) { | |
permutations.push(pattern); | |
} | |
for(let i = 0; i < word.length; i++) { | |
let char = word[i]; | |
let left = word.slice(0, i); | |
let right = word.slice(i + 1); |
This file contains hidden or 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
/** | |
* Definition for a binary tree node. | |
* class TreeNode { | |
* val: number | |
* left: TreeNode | null | |
* right: TreeNode | null | |
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.left = (left===undefined ? null : left) | |
* this.right = (right===undefined ? null : right) |
This file contains hidden or 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
class TreeNode { | |
val: number | |
left: TreeNode | null | |
right: TreeNode | null | |
constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { | |
this.val = (val===undefined ? 0 : val) | |
this.left = (left===undefined ? null : left) | |
this.right = (right===undefined ? null : right) | |
} | |
} |
This file contains hidden or 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
/** | |
Do not return anything, modify nums1 in-place instead. | |
*/ | |
function merge(nums1: number[], m: number, nums2: number[], n: number): void { | |
while (n) { | |
if (nums1[m - 1] > nums2[n - 1]) { | |
nums1[m + n - 1] = nums1[--m]; | |
} else { | |
nums1[m + n - 1] = nums2[--n]; | |
} |
This file contains hidden or 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
// a.k.a famous fibbonaci | |
function climbStairs(n: number): number { | |
if (n <= 1) { | |
return 1; | |
} | |
return climbStairs(n - 1) + climbStairs(n - 2); | |
}; | |
This file contains hidden or 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
class ListNode { | |
val: number; | |
next: ListNode | null; | |
constructor(val?: number, next?: ListNode|null) { | |
this.val = (val===undefined ? 0 : val); | |
this.next = (next===undefined ? null : next); | |
} | |
} | |
function deleteDuplicates(head: ListNode | null): ListNode | null { | |
if(head === null || head.next === null) return head; |
This file contains hidden or 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
/** | |
* Definition for singly-linked list. | |
* class ListNode { | |
* val: number | |
* next: ListNode | null | |
* constructor(val?: number, next?: ListNode | null) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.next = (next===undefined ? null : next) | |
* } | |
* } |
This file contains hidden or 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
function mySqrt(x: number): number { | |
let temp = 0; | |
let sqrt = x / 2; | |
while(temp !== sqrt) { | |
temp = sqrt; | |
sqrt = (x / temp + temp) / 2; | |
} | |
return sqrt; |
This file contains hidden or 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
function addBinary(a: string, b: string): string { | |
return (BigInt(`0b${a}`) + BigInt(`0b${b}`)).toString(2); | |
}; | |
console.log(addBinary("11","1")); // output: 100 | |
console.log(addBinary("1010","1011")); // output: 10101 |
NewerOlder