exhaustive search2 [LeetCode] Implement strStr() 파이썬 (exhaustive search, find, index string) 48ms 걸리는 내 솔루션 class Solution: def strStr(self, haystack: str, needle: str) -> int: m = len(needle) if len(needle) == 0: return 0 for i in range(len(haystack)): if haystack[i] == needle[0] and haystack[i:i+m] == needle: return i else: return -1 20ms 걸리는 솔루션 class Solution: def strStr(self, haystack: str, needle: str) -> int: m, n = len(haystack), len(needle) for i in range(m - n + 1): if haystac.. 2021. 3. 29. [프로그래머스] 카펫 파이썬 완전탐색으로 푸는 방법 def solution(brown, red): for a in range(1, int(red**0.5)+1): if not red % a: b = red // a if 2*a + 2*b + 4 == brown: return [b+2, a+2] 출처: geonlee.tistory.com/114 def solution(brown, red): for index in range(1,red+1): if red%index == 0: length = red//index if (((index+2)*(length+2))-(index*length)) == brown: return [max(index+2,length+2),min(index+2,length+2)] m.blog.naver.com/Post.. 2021. 3. 12. 이전 1 다음