LeetCode 329

[Trees: Trie] 208. Implement Trie (Prefix Tree)

208. Implement Trie (Prefix Tree) https://youtu.be/oobqoCJlHA0?si=rB7vqpOg4d0DiFd1 https://youtu.be/j7Zkw5XWe_Q?si=-yC7nuoxBULmLBuD 이 문제는 Trie(트라이) 자료 구조를 구현하는 것입니다. Trie는 문자열을 효율적으로 저장하고 검색하기 위해 사용되는 트리 형태의 자료 구조입니다. 이 자료 구조는 주로 자동완성, 단어 검색, 접두사 검색과 같은 작업에서 사용됩니다.  Code  # TrieNode 클래스: Trie의 각 노드를 정의class TrieNode: def __init__(self): self.children = {} # 자식 노드를 저장할 해시맵. 키는 문자, 값은 T..

LeetCode/NeetCode 2024.11.09

[LeetCode 75] Medium - 1318. Minimum Flips to Make a OR b Equal to c

1318. Minimum Flips to Make a OR b Equal to c  Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation).Flip operation consists of change any single bit 1 to 0 or change the bit 0 to 1 in their binary representation. Example 1:Input: a = 2, b = 6, c = 5Output: 3Explanation: After flips a = 1 , b = 4 , c = 5 su..

LeetCode/LeetCode75 2024.11.09

[LeetCode 75] Easy - 136. Single Number

136. Single Number class Solution: def singleNumber(self, nums: List[int]) -> int: # 2번 나온거는 무시하고, 1번 나온것만 찾음 # You must implement a solution with a linear runtime complexity and use only constant extra space. # 시간: O(n), 공간: O(1) 으로 풀어야 함 # for 루프 여러개? 단일 변수 여러개? # xor 하면(^) 2번 계산한건 0으로 사라짐 res = nums[0] for i in range(1, len(nums)): ..

LeetCode/Grind169 2024.11.09

714. Best Time to Buy and Sell Stock with Transaction Fee

714. Best Time to Buy and Sell Stock with Transaction Fee https://youtu.be/cUsPoH5DG1Q?si=vWqiiqYgUO8o6U1N Code class Solution: def maxProfit(self, prices: List[int], fee: int) -> int: n = len(prices) # buy[i]: i번째 날에 주식을 구매한 상태에서의 최대 이익 # sell[i]: i번째 날에 주식을 판매한 상태에서의 최대 이익 buy = [0] * n sell = [0] * n # 초기값: # 첫 번째 날에 주식을 구매한 경우: -prices[0] ..

LeetCode/DP심화 2024.11.08