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
Changes from1 commit
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
PrevPrevious commit
NextNext commit
Merge branch 'main' into main
  • Loading branch information
@Ykhan799
Ykhan799 authoredNov 9, 2024
commit4aedd4f94e01cbd2e56f8a5a8be4c70c5792f331
18 changes: 8 additions & 10 deletionstypescript/0303-range-sum-query-immutable.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
class NumArray {
prefix: number[] = [];

prefixSums: number[] = [];

constructor(nums: number[]) {
let cur = 0;
for (const n of nums) {
cur += n;
this.prefix.push(cur);
}
this.prefixSums.push(nums[0]);

for(let i=1; i<nums.length; i++)
this.prefixSums.push(this.prefixSums[i-1] + nums[i])
}

sumRange(left: number, right: number): number {
const rightSum = this.prefix[right],
leftSum = (left > 0) ? this.prefix[left - 1] : 0;

return rightSum - leftSum;
if(left === 0) return this.prefixSums[right];
return this.prefixSums[right] - this.prefixSums[left-1];
}
}

Expand Down
You are viewing a condensed version of this merge commit. You can view thefull changes here.

[8]ページ先頭

©2009-2025 Movatter.jp