Leetcode Problem First Unique Character in a String 문자열 s가 주어졌을 때, s 내에서 유일한 각각의 문자들 중, 첫 번째 문자의 index를 구하는 문제입니다. from collections import Counter class Solution: def firstUniqChar(self, s: s...
Guess Number Higher or Lower
Leetcode Problem Guess Number Higher or Lower 예측한 수와 정답이 맞는지를 비교해주는 guess 함수를 통해 정답을 구하는 문제입니다. class Solution: def guessNumber(self, n: int) -> int: low, high = 0, n while...
Valid Perfect Square
Leetcode Problem Valid Perfect Square 주어진 수 num이 제곱수인지를 판별하는 문제입니다. class Solution: def isPerfectSquare(self, num: int) -> bool: low, high = 0, num // 2 if num > 1 else 1 ...
Intersection of Two Arrays II
Leetcode Problem Intersection of Two Arrays II nums1, nums2 배열이 주어졌을 때, 두 배열의 교집합을 중복을 허용하여 구하는 문제입니다. class Solution: def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:...
Intersection of Two Arrays
Leetcode Problem Intersection of Two Arrays nums1, nums2 배열이 주어졌을 때, 두 배열의 교집합을 구하는 문제입니다. class Solution: def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: ...
Reverse Vowels of a String
Leetcode Problem Reverse Vowels of a String 주어진 s 문자열에서 ‘aeiouAEIOU’ 등의 문자들만 순서를 거꾸로 한 문자열을 반환하는 문제입니다. class Solution: def reverseString(self, s: List[str]) -> None: s.reverse() ...
Reverse String
Leetcode Problem Reverse String 주어진 s 배열의 순서를 in-place 방식으로 거꾸로 뒤집는 문제입니다. class Solution: def reverseString(self, s: List[str]) -> None: s.reverse() python 내장함수로 간단히 해결할 수 있습니다. ...
Power of Four
Leetcode Problem Power of Four 주어진 수 n이 4의 거듭제곱인지를 판별하는 문제입니다. class Solution: def isPowerOfFour(self, n: int) -> bool: low, high = 0, 15 while low <= high: ...
Counting Bits
Leetcode Problem Counting Bits 0부터 n까지를 이진수로 표현했을 때, 1의 개수를 넣은 배열을 구하는 문제입니다. class Solution: def countBits(self, n: int) -> List[int]: arr, i = [0, 1], 2 while i < n + ...
Range Sum Query - Immutable
Leetcode Problem Range Sum Query - Immutable nums 배열과 nums 배열의 left부터 right까지 합을 구하는 함수가 들어간 class를 작성하는 문제입니다. class NumArray: def __init__(self, nums: List[int]): self.nums = nums ...