Leetcode Problem Repeated Substring Pattern 문자열 s가 부분문자열의 반복으로 이루어졌는지 판별하는 문제입니다. class Solution: def repeatedSubstringPattern(self, s: str) -> bool: d, l = 1, len(s) while...
Assign Cookies
Leetcode Problem Assign Cookies 각각의 쿠키의 양이 입력된 배열 s와 필요 쿠키 양이 입력된 아이들의 배열 g가 주어졌을 때, 주어진 쿠키들을 아이들을 최대한 만족하도록 나누는 문제입니다. class Solution: def findContentChildren(self, g: List[int], s: List[int...
Number of Segments in a String
Leetcode Problem Number of Segments in a String 문자열 s가 주어졌을 때, 띄어쓰기를 기준으로 나뉘어진 문자열 조각의 개수를 구하는 문제입니다. class Solution: def countSegments(self, s: str) -> int: return len(s.split()) ...
Third Maximum Number
Leetcode Problem Third Maximum Number 주어진 배열에서 중복을 제외하고 세번째로 큰 수를 구하는 문제입니다. class Solution: def thirdMax(self, nums: List[int]) -> int: return sorted(set(nums))[-3] if len(set(num...
Longest Palindrome
Leetcode Problem Longest Palindrome 주어진 문자열로 만들 수 있는 palindrome 중 최대 길이를 구하는 문제입니다. class Solution: def longestPalindrome(self, s: str) -> int: d, r, f = {}, 0, 0 for c in ...
Convert a Number to Hexadecimal
Leetcode Problem Convert a Number to Hexadecimal 주어진 수를 16진법으로 바꿔서 출력하는 문제입니다. 음수일 경우 보수를 출력합니다. class Solution: def toHex(self, num: int) -> str: return "%x" % num if num >= 0 ...
Sum of Left Leaves
Leetcode Problem Sum of Left Leaves Leaf Node 중 왼쪽 node값의 합을 구하는 문제입니다. class Solution: def sumOfLeftLeaves(self, root: Optional[TreeNode]) -> int: return self.dfs(True, root.left)...
Binary Watch
Leetcode Problem Binary Watch 이진 시계에서 turnedOn 정수가 주어졌을 때, 그 수만큼 모든 경우를 구하는 문제입니다. class Solution: def readBinaryWatch(self, turnedOn: int) -> List[str]: return ['%d:%02d' % (h, m)...
Is Subsequence
Leetcode Problem Is Subsequence 문자열 s와 t가 주어졌을 때 s가 t의 subsequence인지를 판별하는 문제입니다. (s가 t의 subsequence이려면 s의 문자가 모두 t에 들어가있고, 순서가 일치해야 합니다.) class Solution: def isSubsequence(self, s: str, t: s...
Find the Difference
Leetcode Problem Find the Difference 문자열 s와 그 s에 문자 하나를 추가하여 순서를 뒤섞은 문자열 t가 주어졌을 때, 어떤 문자가 추가되었는지를 구하는 문제입니다. from collections import Counter class Solution: def findTheDifference(self, s: st...