Skip to content

Commit 80212b6

Browse files
committedJan 3, 2023
Ruby Solution Plus One
1 parent eff3535 commit 80212b6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
 

‎ruby/0066-plus-one.rb

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def plus_one(digits)
2+
digits.reverse!
3+
carry = 1
4+
i = 0
5+
6+
while(carry ==1)
7+
if (i<digits.length)
8+
if (digits[i]==9)
9+
digits[i]=0
10+
else
11+
digits[i] +=1
12+
carry = 0
13+
end
14+
else
15+
digits.append(1)
16+
carry = 0
17+
end
18+
i+=1
19+
end
20+
21+
return digits.reverse!
22+
end

0 commit comments

Comments
 (0)
Please sign in to comment.