leetcode2 Hash Table 1.Two sum 문제 https://leetcode.com/problems/two-sum/ 문제풀이: Hash table을 이용하여 key = num, value = index의 dictionary를 이용하여 풀이+ ) enumerate() 함수: index와 value값을 모두 전달함 형식:enumerate(iterable obective, start= 0)from typing import Listdef twoSum(nums: List[int], target: int) -> List[int]: hashtable = {} # dictionary 선언#enumerate()함수는 index와 value값을 모두 전달함 for idx, num in enumerate(nums): .. 2024. 6. 11. 코딩테스트 연습(leetcode #231, #202, #415) 231. Power of Two( https://leetcode.com/problems/power-of-two/ )- 내가 작성한 코드(runtime : 41ms, memory: 16.46MB)class Solution: def isPowerOfTwo(self, n: int) -> bool: self.solution = [2**x for x in range(32)] if n in self.solution: return 1 else: return 0- 교수님 코드1(runtime : 36ms, memory: 16.51MB)def solution1(n): if n == 0: return False # 2의 배수와 2의 제곱수 .. 2024. 6. 10. 이전 1 다음