Skip to content

Instantly share code, notes, and snippets.

View HackPoint's full-sized avatar

HackP0!nt HackPoint

  • Israel
View GitHub Profile
@HackPoint
HackPoint / router.tsx
Created June 28, 2023 08:23
say why?
import {
BrowserRouter,
Navigate,
useNavigate,
useRoutes,
} from "react-router-dom";
import { ErrorBoundary } from "src/components/ErrorBoundary";
import { PageLayout } from "src/components/pageLayout/pageLayout";
import {
BooksContextProvider,
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);
/**
* 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)
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)
}
}
/**
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];
}
// a.k.a famous fibbonaci
function climbStairs(n: number): number {
if (n <= 1) {
return 1;
}
return climbStairs(n - 1) + climbStairs(n - 2);
};
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;
/**
* 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)
* }
* }
function mySqrt(x: number): number {
let temp = 0;
let sqrt = x / 2;
while(temp !== sqrt) {
temp = sqrt;
sqrt = (x / temp + temp) / 2;
}
return sqrt;
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