Skip to content

Commit

Permalink
177th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Jul 24, 2024
1 parent 4b2725b commit 0825b64
Show file tree
Hide file tree
Showing 15 changed files with 16 additions and 56 deletions.
3 changes: 3 additions & 0 deletions src/page-1/11. Container With Most Water/maxArea.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
type MaxArea = (height: number[]) => number;

/**
* Accepted
*/
export const maxArea: MaxArea = (height) => {
let [left, right] = [0, height.length - 1];
let maxArea = 0;
Expand Down
5 changes: 0 additions & 5 deletions src/page-1/38. Count and Say/countAndSay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ type CountAndSay = (n: number) => string;

/**
* Accepted
*
* 1 -> read: one 1 = 11
* 11 -> read: two 1s = 21
* 21 -> read: one 2, one 1 = 1211
* 1211 -> read: one 1, one 2, two 1s = 111221
*/
export const countAndSay: CountAndSay = (n) => {
let result = '1';
Expand Down
8 changes: 0 additions & 8 deletions src/page-1/54. Spiral Matrix/spiralOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ type SpiralOrder = (matrix: number[][]) => number[];

/**
* Accepted
*
* first lap
* 1. up: left -> right
* 2. right: up -> down
* 3. down: right -> left
* 4. left: down -> up
* second lap (-1)
* ...
*/
export const spiralOrder: SpiralOrder = (matrix) => {
const result = [];
Expand Down
4 changes: 0 additions & 4 deletions src/page-1/69. Sqrt(x)/mySqrt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type MySqrt = (x: number) => number;

/**
* Accepted
*
* Math
*/
export const mySqrt: MySqrt = (x) => {
let result = x;
Expand All @@ -17,8 +15,6 @@ export const mySqrt: MySqrt = (x) => {

/**
* Accepted
*
* Binary Search
*/
export const mySqrt2: MySqrt = (x) => {
let [left, right] = [0, x];
Expand Down
3 changes: 0 additions & 3 deletions src/page-1/70. Climbing Stairs/climbStairs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ type ClimbStairs = (n: number) => number;

/**
* Accepted
*
* 1 step from the n - 1 ladder
* 2 steps from the n - 2 ladder
*/
export const climbStairs: ClimbStairs = (n) => {
const temp = [1, 2];
Expand Down
9 changes: 7 additions & 2 deletions src/page-1/8. String to Integer (atoi)/myAtoi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export function myAtoi(s: string): number {
type MyAtoi = (s: string) => number;

/**
* Accepted
*/
export const myAtoi: MyAtoi = (s) => {
const INT_MAX = 2 ** 31 - 1;
const INT_MIN = -(2 ** 31);

Expand Down Expand Up @@ -34,4 +39,4 @@ export function myAtoi(s: string): number {
}

return result * sign;
}
};
3 changes: 3 additions & 0 deletions src/page-14/1480. Running Sum of 1d Array/runningSum.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
type RunningSum = (nums: number[]) => number[];

/**
* Accepted
*/
export const runningSum: RunningSum = (nums) => {
// Initialize an array to store the running sums
const result: number[] = [];
Expand Down
4 changes: 0 additions & 4 deletions src/page-2/136. Single Number/singleNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ type SingleNumber = (nums: number[]) => number;

/**
* Accepted
*
* [2,2,1] => [010,010,001]
* 1. 010 ^ 010 = 000
* 2. 000 ^ 001 = 001 -> 1
*/
export const singleNumber: SingleNumber = (nums) => {
return nums.reduce((sum, num) => sum ^ num);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ type Intersection = (nums: number[][]) => number[];

/**
* Accepted
*
* [A, B, C]
* A vs B -> current
* current vs C -> result
*/
export const intersection: Intersection = (nums) => {
let result = new Set<number>(nums[0]);
Expand All @@ -31,8 +27,6 @@ export const intersection: Intersection = (nums) => {

/**
* Accepted
*
* Counting
*/
export const intersection2: Intersection = (nums) => {
const result = [] as number[];
Expand Down
6 changes: 0 additions & 6 deletions src/page-3/231. Power of Two/isPowerOfTwo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ type IsPowerOfTwo = (n: number) => boolean;

/**
* Accepted
*
* Math
*/
export const isPowerOfTwo: IsPowerOfTwo = (n) => {
return Number.isInteger(Math.log2(n));
};

/**
* Accepted
*
* Bit Manipulation
*/
export const isPowerOfTwo2: IsPowerOfTwo = (n) => {
if (n === 0) return false;
Expand All @@ -22,8 +18,6 @@ export const isPowerOfTwo2: IsPowerOfTwo = (n) => {

/**
* Accepted
*
* Recursion
*/
export const isPowerOfTwo3: IsPowerOfTwo = (n) => {
if (n === 0) return false;
Expand Down
4 changes: 0 additions & 4 deletions src/page-4/326. Power of Three/isPowerOfThree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ type IsPowerOfThree = (n: number) => boolean;

/**
* Accepted
*
* Math
*/
export const isPowerOfThree: IsPowerOfThree = (n) => {
return n > 0 && (Math.log10(n) / Math.log10(3)) % 1 === 0;
};

/**
* Accepted
*
* Recursion
*/
export const isPowerOfThree2: IsPowerOfThree = (n) => {
if (n === 0) return false;
Expand Down
8 changes: 0 additions & 8 deletions src/page-4/338. Counting Bits/countBits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ type CountBits = (n: number) => number[];

/**
* Accepted
*
* num = 5
* 0 0 0 0 -> 0
* 0 0 0 1 -> 1 => Start using `for` loops
* 0 0 1 0 -> 1
* 0 0 1 1 -> 2
* 0 1 0 0 -> 1
* 0 1 0 1 -> 2
*/
export const countBits: CountBits = (n) => {
const result = [];
Expand Down
4 changes: 0 additions & 4 deletions src/page-4/344. Reverse String/reverseString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type ReverseString = (s: string[]) => void;

/**
* Accepted
*
* Two Pointers
*/
export const reverseString: ReverseString = (s) => {
for (let i = 0, j = s.length - 1; i < j; i++, j--) {
Expand All @@ -15,8 +13,6 @@ export const reverseString: ReverseString = (s) => {

/**
* Accepted
*
* String
*/
export const reverseString2: ReverseString = (s) => {
s.reverse();
Expand Down
2 changes: 0 additions & 2 deletions src/page-5/504. Base 7/convertToBase7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ type ConvertToBase7 = (num: number) => string;

/**
* Accepted
*
* Math
*/
export const convertToBase7: ConvertToBase7 = (num) => {
if (num === 0 || num === 1) return String(num);
Expand Down
3 changes: 3 additions & 0 deletions src/page-9/938. Range Sum of BST/rangeSumBST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import type { TreeNode } from '~/utils/binary-tree';

type RangeSumBST = (root: TreeNode | null, low: number, high: number) => number;

/**
* Accepted
*/
export const rangeSumBST: RangeSumBST = (root, low, high) => {
if (!root) return 0;
if (root.val < low) return rangeSumBST(root.right, low, high);
Expand Down

0 comments on commit 0825b64

Please sign in to comment.