Last active
April 9, 2020 14:47
-
-
Save master-stm/70824e5235e99da55eeeeb7621d26c03 to your computer and use it in GitHub Desktop.
a solution to the plus one problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
given an array of integers that represents the digits of | |
a positive integers, you are asked to add 1 to it and return | |
the new value of the array''' | |
# input: [2, 3, 6] => output: [2, 3, 7] | |
# input: [2, 9, 9] => output: [3, 0, 0] | |
# code starts here # | |
list1 = [2, 3, 6] | |
list2 = [2, 9, 9] | |
list3 = [4, 3, 3] | |
def plusOne(list): | |
newList = [] | |
Mylist = [] | |
for i in list: | |
newList.append(str(i)) | |
newList = int(''.join(newList)) | |
newList = newList + 1 | |
newList = str(newList) | |
for i in newList: | |
Mylist.append(int(i)) | |
print(Mylist) | |
plusOne(list1) | |
plusOne(list2) | |
plusOne(list3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment