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

Commit350acd9

Browse files
committed
add 67
1 parenteba61e8 commit350acd9

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

‎Easy/303-rangeSumQuery.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Key: Dynamic Programming
3+
*
4+
*@constructor
5+
*@param {number[]} nums
6+
*/
7+
varNumArray=function(nums){
8+
this.sums=[0];
9+
for(vari=1;i<=nums.length;i++){
10+
this.sums[i]=this.sums[i-1]+nums[i-1];
11+
}
12+
};
13+
14+
/**
15+
*@param {number} i
16+
*@param {number} j
17+
*@return {number}
18+
*/
19+
NumArray.prototype.sumRange=function(i,j){
20+
returnthis.sums[j+1]-this.sums[i];
21+
};
22+
23+
24+
/**
25+
* Your NumArray object will be instantiated and called as such:
26+
* var numArray = new NumArray(nums);
27+
* numArray.sumRange(0, 1);
28+
* numArray.sumRange(0, 2);
29+
*/

‎Easy/67-addBinary.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ var addBinary = function(a, b) {
99
varaLength=a.length;
1010
varbLength=b.length;
1111
vari=0;
12+
13+
// add '0' before the shorted binary string
1214
if(aLength<=bLength){
1315
i=bLength-1;
1416
for(varj=0;j<bLength-aLength;j++){
@@ -21,6 +23,7 @@ var addBinary = function(a, b) {
2123
}
2224
}
2325

26+
// extra is 1 if there is a carry
2427
while(i>=0){
2528
if(extra===0){
2629
result[i]=a[i]^b[i];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp