Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:Each row must contain the digits 1-9 without repetition.Each column must contain the digits 1-9 without repetition.Each of the nine 3 x 3 sub-boxes of the grid must contain the digits 1-9 without repetition.Note:A Sudoku board (partially filled) could be valid but is not necess..
μ€λΈμ
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.You must write an algorithm that runs in O(n) time.longest consecutive sequenceλ₯Ό μ°Ύλ λ¬Έμ ! O(n) μμΌλ‘ νμ΄μΌ νλ€.μ£Όμν μ μ constraintsμ numsμ lengthκ° 0λΆν° κ°λ₯νλ€λ κ² Hash Setμ μ΄μ©ν νμ΄class Solution: def longestConsecutive(self, nums: List[int]) -> int: numSet = set(nums) longest = 0 f..
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.Given a string s, return true if it is a palindrome, or false otherwise.μ ν¨ν palindrome(νλ¬Έ) κ²μ¬νλ λ©μλ ꡬννκΈ°! νμ΄1: Reverse Stringclass Solution: def isPalindrome(self, s:..
Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of brackets.Open brackets must be closed in the correct order.Every close bracket has a corresponding open bracket of the same type.κ΄νΈκ° μ¬λ°λ₯΄κ² μ§μ§μ΄μ‘λμ§ νμΈνλ λ¬Έμ ! νμ΄1: Stack μ΄μ©class Solution: def isValid(sel..
μ λ€λ¦(Generic)μ΄λ?Cλ μλ° κ°μ μ μ μΈμ΄μμ λ€μν νμ
κ°μ μ¬μ¬μ©μ±μ λμ΄κΈ° μν΄ μ¬μ©νλ λ¬Έλ²μ΄λ€. νμ
μ€ν¬λ¦½νΈλ μ μ νμ
μ κ°μ§λ―λ‘ μ λ€λ¦ λ¬Έλ²μ μ§μνλ€.μ λ€λ¦μ μ¬μ μ μλ―Έλ μΌλ°μ μΈ κ²(general)μ λ»νλλ°, νμ
μ€ν¬λ¦½νΈμ μ λ€λ¦λ μ΄μ λΉμ·νκ² 'μΌλ°νλ λ°μ΄ν°' νμ
μ΄λΌ λ³Ό μ μλ€.μ λ€λ¦: ν¨μ, νμ
, ν΄λμ€ λ±μμ λ΄λΆμ μΌλ‘ μ¬μ©ν νμ
μ 미리 μ ν΄λμ§ μκ³ νμ
λ³μλ₯Ό μ¬μ©ν΄μ ν΄λΉ μμΉλ₯Ό λΉμ λ λ€μμ, μ€μ λ‘ κ·Έ κ°μ μ¬μ©ν λ μΈλΆμμ νμ
λ³μ μ리μ νμ
μ μ§μ νμ¬ μ¬μ©νλ λ°©μ-> μ΄λ κ² νλ©΄ ν¨μ, νμ
, ν΄λμ€ λ± μ¬λ¬ νμ
μ λν΄ νλνλ λ°λ‘ μ μνμ§ μμλ λκΈ° λλ¬Έμ μ¬μ¬μ©μ±μ΄ ν¬κ² ν₯μλλ€.νμ
λ³μλ μΌλ°μ μΌλ‘ μ κ°μ΄ κΊΎμ κ΄νΈ λ΄λΆμ..
Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.λΉλμκ° λμ μμλλ‘, μμ kκ°μ elementsλ₯Ό μΆλ ₯νλ λ¬Έμ λ€. νμ΄ 1class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: count = defaultdict(int) for i in nums: count[i] += 1 result = sorted(count, key=count.get, reverse=Tr..