문제 : https://leetcode.com/problems/find-the-town-judge/description/ 난이도 : Lv.1 풀이 class Solution: def findJudge(self, n: int, trust: List[List[int]]) -> int: if not trust: if n == 1: return 1 else: return -1 relationship = [[] for _ in range(n+1)] for a, b in trust: #a는 b를 신뢰 relationship[b].append(a) for i in range(1, n+1): if len(relationship[i]) == n-1: for t in range(1, n+1): if i in relatio..
문제 : https://leetcode.com/problems/longest-common-prefix/description/ 난이도 : Easy 풀이 class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: if len(strs) == 1: return strs[0] strs = sorted(strs) minLen = min(len(strs[0]), len(strs[-1])) i = 0 while i < minLen and strs[0][i] == strs[-1][i]: i += 1 prefix = strs[0][0:i] return prefix 배열을 다 훑어서 하나하나 비교해야 될 것 같지만, 사실은 오름차순 정렬 후 처음과 끝의 ..