반응형 SWE326 [Leetcode][python3] 7. Reverse Integer Problem: Code 1 : I used String API in Python. First, convert Integer X to String Second, check if last character is 0 or not reverse string class Solution: def reverse(self, x: int) -> int: if x == 0: return 0 s = str(x) negativeFlag = 1 if s[0] == '-': negativeFlag = -1 s = s[1:] index = 0 while index (2**31-1) or (-2**31)>result : return 0 return result Code 2: I'm not sure if it is right way.. 2022. 3. 8. HackerRank - Tree: Huffman Decoding 문제 : https://www.hackerrank.com/challenges/tree-huffman-decoding/problem?h_r=internal-search 해결 코드 : import sys sys.setrecursionlimit(2000) def decodeHuff(root, s): result = [] def _recursive(cur, root, binary): #print(f'cur.data{cur.data} binary{binary}') if cur.left==None and cur.right==None : result.append(cur.data) return _recursive(root, root, binary) if not binary: return if binary[0] == '.. 2022. 3. 6. HackerRank - AND xor OR 문제 이해 안감 ㅜ 문제 : https://www.hackerrank.com/challenges/and-xor-or/problem sample input에서 3,5,2 가 뭔지 모르겠음 5 9 6 3 5 2 2022. 3. 5. HackerRank - Queue using Two Stacks 문제 : https://www.hackerrank.com/challenges/queue-using-two-stacks/problem 해결 코드 : 6문제 time limit 나옴 ㅠㅠ (6/15) stack1 = [] stack2 = [] def enque(num): stack1.append(num) def deque() : #pop from stack1 #push to stack2 while len(stack1) : stack2.append(stack1.pop()) #deque stack2.pop() #reset while len(stack2) : #pop from stack2 #push to stack1 stack1.append(stack2.pop()) def printFront(): print(st.. 2022. 3. 5. 이전 1 ··· 13 14 15 16 17 18 19 ··· 82 다음 반응형