Skip to content

Commit

Permalink
144th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Jun 10, 2024
1 parent 92ff159 commit 652a1a2
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 71 deletions.
11 changes: 0 additions & 11 deletions src/page-1/20. Valid Parentheses/is-valid.spec.ts

This file was deleted.

9 changes: 9 additions & 0 deletions src/page-1/20. Valid Parentheses/isValid.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { isValid } from './isValid';

describe('20. Valid Parentheses', () => {
test('isValid', () => {
expect(isValid('()')).toBe(true);
expect(isValid('()[]{}')).toEqual(true);
expect(isValid('(]')).toEqual(false);
});
});
File renamed without changes.
22 changes: 0 additions & 22 deletions src/page-1/21. Merge Two Sorted Lists/merge-two-lists.spec.ts

This file was deleted.

30 changes: 30 additions & 0 deletions src/page-1/21. Merge Two Sorted Lists/mergeTwoLists.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { stringify } from 'flatted';

import { generateLinkedList } from '~/utils/linked-list';

import { mergeTwoLists } from './mergeTwoLists';

describe('21. Merge Two Sorted Lists', () => {
test('mergeTwoLists', () => {
{
const list1 = generateLinkedList([1, 2, 4]);
const list2 = generateLinkedList([1, 3, 4]);
const expected = generateLinkedList([1, 1, 2, 3, 4, 4]);
expect(stringify(mergeTwoLists(list1, list2))).toBe(stringify(expected));
}

{
const list1 = generateLinkedList([]);
const list2 = generateLinkedList([]);
const expected = generateLinkedList([]);
expect(stringify(mergeTwoLists(list1, list2))).toBe(stringify(expected));
}

{
const list1 = generateLinkedList([]);
const list2 = generateLinkedList([0]);
const expected = generateLinkedList([0]);
expect(stringify(mergeTwoLists(list1, list2))).toBe(stringify(expected));
}
});
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { removeDuplicates } from './removeDuplicates';

describe('26. Remove Duplicates from Sorted Array', () => {
test('removeDuplicates', () => {
{
const nums = [1, 1, 2];
expect(removeDuplicates(nums)).toBe(2);
expect(nums).toStrictEqual([1, 2]);
}

{
const nums = [0, 0, 1, 1, 1, 2, 2, 3, 3, 4];
expect(removeDuplicates(nums)).toBe(5);
expect(nums).toStrictEqual([0, 1, 2, 3, 4]);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ export const removeDuplicates: RemoveDuplicates = (nums) => {
const result = Array.from(new Set(nums));
nums.length = 0;
nums.push(...result);

return new Set(nums).size;
};
8 changes: 0 additions & 8 deletions src/page-1/27. Remove Element/remove-element.spec.ts

This file was deleted.

19 changes: 19 additions & 0 deletions src/page-1/27. Remove Element/removeElement.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { removeElement } from './removeElement';

describe('27. Remove Element', () => {
test('removeElement', () => {
{
const nums = [3, 2, 2, 3];
const expected = [2, 2];
expect(removeElement(nums, 3)).toBe(expected.length);
expect(nums.sort()).toStrictEqual(expected.sort());
}

{
const nums = [0, 1, 2, 2, 3, 0, 4, 2];
const expected = [0, 1, 4, 0, 3];
expect(removeElement(nums, 2)).toBe(expected.length);
expect(nums.sort()).toStrictEqual(expected.sort());
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { strStr } from './strStr';

describe('28. Find the Index of the First Occurrence in a String', () => {
test('strStr', () => {
expect(strStr('sadbutsad', 'sad')).toBe(0);
expect(strStr('leetcode', 'leeto')).toBe(-1);
});
});
8 changes: 0 additions & 8 deletions src/page-1/28. Implement strStr()/str-str.spec.ts

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { searchRange, searchRange2 } from './searchRange';

describe('34. Find First and Last Position of Element in Sorted Array', () => {
it('searchRange', () => {
expect(searchRange([5, 7, 7, 8, 8, 10], 8)).toStrictEqual([3, 4]);
expect(searchRange([5, 7, 7, 8, 8, 10], 6)).toStrictEqual([-1, -1]);
expect(searchRange([], 0)).toStrictEqual([-1, -1]);
});

it('searchRange2', () => {
expect(searchRange2([5, 7, 7, 8, 8, 10], 8)).toStrictEqual([3, 4]);
expect(searchRange2([5, 7, 7, 8, 8, 10], 6)).toStrictEqual([-1, -1]);
expect(searchRange2([], 0)).toStrictEqual([-1, -1]);
});
});

0 comments on commit 652a1a2

Please sign in to comment.