I've wrote my answer code and tried to run it on the LeetCode playgroundhttps://leetcode.com/playground/.
In the part of
print(check_num)
print(check_num[len(check_num)-1])
it was revealed that the program can receive the input and its last character.
class Solution:
def reverse(self, x: int) -> int:
check_num = str(x)
flag = 0
if(check_num[0] == '-'):
check_num = check_num[1:]
flag = 0
print(check_num)
print(check_num[len(check_num)-1])
else if (check_num[len(check_num)-1] == '0'):
check_num = check_num[:len(check_num)-1]
#reverse
storage = ['a'] * len(check_num) - 1
for i in range(len(check_num)):
num = -i
storage[i] = check_num[num]
if(flag == 1):
storage.insert(0, '-')
#turn to string
oneLinerString=""
for x in storage:
oneLinerString += x
return int(oneLinerString)
def main():
import sys
import io
def readlines():
for line in io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8'):
yield line.strip('\n')
lines = readlines()
while True:
try:
line = next(lines)
x = int(line);
ret = Solution().reverse(x)
out = str(ret);
print(out)
except StopIteration:
break
if __name__ == '__main__':
main()
How should I fix my current code?
Finished in N/A
Line 12: SyntaxError: invalid syntax