Skip to content

Commit 93269ba

Browse files
committed
plusOne
1 parent bd484e7 commit 93269ba

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

plusOne.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {number[]} digits
3+
* @return {number[]}
4+
*/
5+
var plusOne = function(digits) {
6+
let revArray = digits.reverse(),
7+
add = true,
8+
index = 0
9+
10+
while(add){
11+
if (revArray[index] === 9){
12+
revArray[index++] = 0
13+
} else {
14+
revArray[index] ? revArray[index] += 1: revArray[index] = 1;
15+
add = false;
16+
}
17+
}
18+
19+
return revArray.reverse();
20+
};

0 commit comments

Comments
 (0)