알고리즘 (28) 썸네일형 리스트형 [파이썬 알고리즘 인터뷰] 두 수의 합 Two Sum - 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 나의풀이 def twoSum(self, nums: List[int], target: int) -> List[int]: answer=[] for i in range(len(nums)-1): if (target-nums[i]) in nums[i+1:]: answer.append(i) answer.append(nums[i+1:].index(target-nums[i])+(i+1)) return answer.. [파이썬 알고리즘 인터뷰]그룹 애너그램 Group Anagrams - 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 나의 풀이 def groupAnagrams(self, strs: List[str]) -> List[List[str]]: keys=[] anagrams={} answer=[] for s in strs: sort_str=sorted(s) sort_str=''.join(sort_str) if sort_str in keys: anagrams[sort_str].append(s) else: key.. [파이썬 알고리즘 인터뷰] 가장 흔한 단어 Most Common Word - 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 나의풀이 def mostCommonWord(self, paragraph: str, banned: List[str]) -> str: sol={} # 특수문자 전처리 for p in paragraph: if p in ['!','?','\'',';','.',',']: paragraph = paragraph.replace(p,' ') paragraph=paragraph.lower() par.. [파이썬 알고리즘 인터뷰] 로그파일 재정렬 Reorder Data in Log Files - 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 나의풀이 def reorderLogFiles(self, logs: List[str]) -> List[str]: s=[] n=[] for idx,log in enumerate(logs): temp=list(log.split(' ')) try: int(temp[1]) n.append(log) except: s.append(log) # 같은 문자일 경우 식별자에 따라 정렬.. [파이썬 알고리즘 인터뷰] 문자열 뒤집기 Reverse String - 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 나의 풀이 def reverseString(self, s : List[str]) -> None: s = s[::-1] 원래는 정상적으로 작동해야 하는 코드이지만 리트코드의 특성 상 작동하지 않는다. s[:]=s[::-1]로 트릭을 사용할 수 있지만... 이를 생각한다는게 흠.... 풀이 # 1 def reverseString(self, s : List[str]) -> None: left.. [파이썬 알고리즘 인터뷰] 유효한 팰린드롬 Valid Palindrome - 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 풀이 # 1 def isPalindrome(self, s:str) -> bool: strs=[] for char in s: if char.isalnum(): strs.append(char.lower()) # 팰린드롬 여부 판별 while len(strs) > 1: if strs.pop(0)!=strs.pop(): return False return True str.isalnum() .. [프로그래머스] level1 - 숫자 문자열과 영단어 코딩테스트 연습 - 숫자 문자열과 영단어 네오와 프로도가 숫자놀이를 하고 있습니다. 네오가 프로도에게 숫자를 건넬 때 일부 자릿수를 영단어로 바꾼 카드를 건네주면 프로도는 원래 숫자를 찾는 게임입니다. 다음은 숫자의 일부 자 programmers.co.kr 나의코드 def solution(s): s = s.replace('one','1') s = s.replace('two','2') s = s.replace('three','3') s = s.replace('four','4') s = s.replace('five','5') s = s.replace('six','6') s = s.replace('seven','7') s = s.replace('eight','8') s = s.replace('nine','9'.. [프로그래머스] Level1 - 신규 아이디 추천* 코딩테스트 연습 - 신규 아이디 추천 카카오에 입사한 신입 개발자 네오는 "카카오계정개발팀"에 배치되어, 카카오 서비스에 가입하는 유저들의 아이디를 생성하는 업무를 담당하게 되었습니다. "네오"에게 주어진 첫 업무는 새로 programmers.co.kr 나의코드 import re def solution(new_id): answer = '' new_id=new_id.lower() chars = "~!@#$%^&*()=+[{]}:?,/" for c in range(len(chars)): new_id=new_id.replace(chars[c],"") new_id=re.sub('[.]+', '.', new_id) new_id=new_id.strip('.') if len(new_id)==0: new_id='a' .. 이전 1 2 3 4 다음