Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 62eb49b

Browse files
authored
most asked technical interview question plus one added.
1 parent 69ee702 commit 62eb49b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

LeetcodeProblems/Algorithms/plus1.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var plusOne = function(digits) {
2+
result=[]; carry=1; n=digits.length-1;
3+
for(i=n; i>=0; i--){
4+
sum=(carry+digits[i])%10;
5+
carry=Math.floor((carry+digits[i])/10);
6+
result[n]=sum;
7+
n--;
8+
}
9+
if(carry!==0) {result.unshift(carry);}
10+
return result;
11+
};

0 commit comments

Comments
 (0)