Home
icyou
Cancel

Power of Three

Leetcode Problem Power of Three 주어진 수가 3의 거듭제곱인지를 판별하는 문제입니다. class Solution: def isPowerOfThree(self, n: int) -> bool: low, high = 0, 31 while low <= high: ...

Nim Game

Leetcode Problem Nim Game Nim game에서 n개의 stone이 주어졌을 때 이길 수 있는 경우를 판별하는 문제입니다. class Solution: def canWinNim(self, n: int) -> bool: return False if n % 4 == 0 else True 경우의 수를 1부터...

Word Pattern

Leetcode Problem Word Pattern 주어진 문자열 s의 형식이 pattern 문자열 형식과 일치하는지를 판별하는 문제입니다. class Solution: def wordPattern(self, pattern: str, s: str) -> bool: d, arr = {}, s.split() ...

Move Zeroes

Leetcode Problem Move Zeroes nums 배열을 in-place 방식으로 0을 배열의 맨 뒤로 보내는 문제입니다. class Solution: def moveZeroes(self, nums: List[int]) -> None: """ Do not return anything, modify...

First Bad Version

Leetcode Problem First Bad Version 1부터 n번째까지의 version이 있을 때 처음 발생한 잘못된 version을 isBadVersion 함수를 이용하여 찾는 문제입니다. class Solution: def firstBadVersion(self, n: int) -> int: low = 1 ...

Implement Rand10() Using Rand7()

Leetcode Problem Implement Rand10() Using Rand7() Rand7() 함수를 이용해서 Rand10()을 구현하는 문제입니다. 동일한 확률로 각 정수가 출력되어야 합니다. class Solution: def rand10(self): """ :rtype: int """...

Power of Two

Leetcode Problem Power of Two 주어진 수 n이 2의 거듭제곱이 되는 수인지를 판별하는 문제입니다. class Solution: def isPowerOfTwo(self, n: int) -> bool: x = 0 while x < n: if 2 ** x == n...

Summary Ranges

Leetcode Problem Summary Ranges 주어진 nums 배열을 다 포함하는 범위를 나타내는 새로운 배열을 만드는 문제입니다. class Solution: def summaryRanges(self, nums: List[int]) -> List[str]: arr = [] if not nums:...

Implement Queue using Stacks

Leetcode Problem Implement Queue using Stacks 두 개의 stack을 이용하여 queue를 구현하는 문제입니다. class MyQueue: def __init__(self): self.stack1 = [] self.stack2 = [] def push(self, x: ...

Implement Stack using Queues

Leetcode Problem Implement Stack using Queues 두 개의 queue를 이용하여 stack을 구현하는 문제입니다. class MyStack: def __init__(self): self.q1 = deque() self.q2 = deque() def push(self, x...