Home
icyou
Cancel

Number of 1 Bits

Leetcode Problem Number of 1 Bits 32bit의 양수형 정수가 주어졌을 때, 1의 개수를 구하는 문제입니다. class Solution: def hammingWeight(self, n: int) -> int: return bin(n).count('1') 내부함수를 이용하여 간단하게 구해줬습니다....

Reverse Bits

Leetcode Problem Reverse Bits 32bit의 양수형 정수가 주어졌을 때, 이 수의 bit를 전부 거꾸로 뒤집었을 때 나오는 수를 구하는 문제입니다. class Solution: def reverseBits(self, n: int) -> int: s = bin(n)[:1:-1] retur...

Excel Sheet Column Number

Leetcode Problem Excel Sheet Column Number Excel Column이 주어졌을 때, 몇 번째 줄인지를 구하는 구하는 문제입니다. class Solution: def titleToNumber(self, columnTitle: str) -> int: rs, steps = 0, 1 ...

Majority Element

Leetcode Problem Majority Element 주어진 배열 내에서 배열 전체 개수의 절반 이상이 나오는 수를 구하는 문제입니다. class Solution: def majorityElement(self, nums: List[int]) -> int: d = {} x = 0 for ...

Excel Sheet Column Title

Leetcode Problem Excel Sheet Column Title columnNumber가 주어졌을 때, Excel의 column 이름을 구하는 문제입니다. class Solution: def convertToTitle(self, columnNumber: int) -> str: return self.convert...

Intersection of Two Linked Lists

Leetcode Problem Intersection of Two Linked Lists 두 linked-list가 합쳐지는 부분의 노드를 구하는 문제입니다. class Solution: def getList(self, head: ListNode): return [head.val] + self.getList(head.next)...

Linked List Cycle

Leetcode Problem Linked List Cycle 주어진 linked list가 cycle이 있는지를 판별하는 문제입니다. class Solution: def hasCycle(self, head: Optional[ListNode]) -> bool: while head: if head.va...

Single Number

Leetcode Problem Single Number 정수들의 모여 있는 배열에서 한 개만 있는 정수를 출력하는 문제입니다. class Solution: def singleNumber(self, nums: List[int]) -> int: arr = [0] * 60001 for n in nums: ...

Valid Palindrome

Leetcode Problem Valid Palindrome 주어진 문자열을 공백, 특수문자를 제거하고 전부 소문자 형식으로 만들었을 때 palindrom인지를 판별하는 문제입니다. import re class Solution: def isPalindrome(self, s: str) -> bool: s = re.sub(r...

Best Time to Buy and Sell Stock

Leetcode Problem Best Time to Buy and Sell Stock 주식의 가격이 적힌 배열이 주어지고, 이 주식을 사고 판다고 가정할 때 얻을 수 있는 최대 수익을 계산하는 문제입니다. class Solution: def maxProfit(self, prices: List[int]) -> int: p...