Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Create 0303-range-sum-query-immutable.ts, 0705-design-hashset.ts#3103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Ykhan799 merged 6 commits intoneetcode-gh:mainfromD00NIK:main
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
2 changes: 1 addition & 1 deletiontypescript/0303-range-sum-query-immutable.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
class NumArray {

prefixSums: number[] = [];

constructor(nums: number[]) {
Expand Down
65 changes: 65 additions & 0 deletionstypescript/0705-design-hashset.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
class _ListNode { // ListNode has a confict
key: number;
next: _ListNode | undefined;

constructor(key: number) {
this.key = key;
}
}

class MyHashSet {
readonly ARRAY_LENGTH = Math.pow(10, 4);
set = new Array<_ListNode>(this.ARRAY_LENGTH);

constructor() {
for (let i = 0; i < this.ARRAY_LENGTH; i++)
this.set[i] = new _ListNode(0);
}

add(key: number): void {
let cur = this.set[key % this.set.length];

while (cur.next) {
if (cur.next.key === key)
return;

cur = cur.next;
}

cur.next = new _ListNode(key);
}

remove(key: number): void {
let cur = this.set[key % this.set.length];

while (cur.next) {
if (cur.next.key === key) {
cur.next = cur.next.next;
return;
}

cur = cur.next;
}
}

contains(key: number): boolean {
let cur = this.set[key % this.set.length];

while (cur.next) {
if (cur.next.key === key)
return true;

cur = cur.next;
}

return false;
}
}

/**
* Your MyHashSet object will be instantiated and called as such:
* var obj = new MyHashSet()
* obj.add(key)
* obj.remove(key)
* var param_3 = obj.contains(key)
*/

[8]ページ先頭

©2009-2025 Movatter.jp