릿코드 5 - Longest Palindromic Substring
class Solution: def longestPalindrome(self, s: str) -> str: answer = [0, 0] for i in range(1, len(s)-1): l, r = i, i while True : if s[l] == s[r]: l, r = l - 1, r + 1 if l == -1 or r == len(s): l, r = l + 1, r - 1 break else : l, r = l + 1, r - 1 break if answer[1] - answer[0] < r - l: answer = [l, r] for i in range(0, len(s) - 1): if s[i] == s[i + 1]: l, r = i, i + 1 while True : if s[l] == s[r..
더보기
프로그래머스5 - 방의 개수
def solution(arrows): direction = [ [0,1], [1,1], [1,0], [1,-1], [0,-1], [-1,-1], [-1,0], [-1,1], ] answer = 0 dic = {} path = {} x, y = 0, 0 dic[str([x, y])] = True for item in arrows: for i in range(2) : nextx, nexty = x + direction[item][0], y + direction[item][1] pathKey = str([x, y, nextx, nexty]) pathKey2 = str([nextx, nexty, x, y]) dicKey = str([nextx, nexty]) if not dicKey in dic : path[..
더보기