본문 바로가기
반응형

SWE/코테137

[Leetcode][python] 33. Search in Rotated Sorted Array problem : https://leetcode.com/problems/search-in-rotated-sorted-array/ code : class Solution: def search(self, nums: List[int], target: int) -> int: def findPivot(nums): left = 0 right = len(nums)-1 while left nums[mid]: return mid if nums[mid] > nums[0] : left = mid+1 else: right = mid-1 return 0 def binarySearch(nums, left, right, target): while lefttarget : return binarySearch(nums, pivot, l.. 2022. 4. 1.
[Leetcode][python] 15. 3Sum problem: code: #Input: nums = [-1,0,1,2,-1,-4] # currentArray : -1, 0 # resultArray : [-1, 0, 1] class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: result = [] def checkExists(num1, num2, num3): for items in result: if (num1 in items) and (num2 in items) and (num3 in items): return True return False #traversal num allZeroFlag = False for i in range(len(nums)): # N for j in r.. 2022. 3. 31.
[Leetcode][python]36. Valid Sudoku problem: code : from collections import defaultdict # dictionay = hashmap # multiple values -> defaultdictionary class Solution: def isValidSudoku(self, board: List[List[str]]) -> bool: # 3 Hashmaps # - Key : row # - Key : column # - Key : 9 section # hash function to get key with (row, column) # key = 3*int(row/3) + column//3 rowHash = defaultdict() colHash = defaultdict() secHash = defaultdict.. 2022. 3. 29.
[Leetcode][python] 17 Letter Combinations of a Phone number problem : https://leetcode.com/problems/letter-combinations-of-a-phone-number/ Letter Combinations of a Phone Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com code: from collections import defaultdict # 1. make phone digits hashmap d = defaultdict() asciiValue = 97 # 'a' fo.. 2022. 3. 28.
반응형