본문 바로가기
반응형

분류 전체보기128

[DSA][Array & Hashing] 07. Valid Sudoku LeetCode 36 07. Valid SudokuDetermine 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) coul.. 2025. 5. 21.
[DSA][Array & Hashing] 06. Product of Array Except Self LeetCode 238 06. Product of Array Except SelfGiven an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.You must write an algorithm that runs in O(n) time and without using the division operation. [질문하기]- 배열에 0이 하나 이상 포함될 수 있나요? [아.. 2025. 5. 20.
[DSA][Array & Hashing] 05. Top K Frequent Elements LeetCode 347 05. Top K Frequent ElementsGiven an integer array nums and an integer k, return the k most frequent elements.You may return the answer in any order. [질문하기]- 빈도가 같은 요소가 여러 개 있는 경우 모두 반환해야 하나요?- 배열에 음수도 포함될 수 있나요? YES [아이디어]- 정렬- Heap- Bucket Sort [풀이 1] Hash with Sortingclass Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: # 1. 빈도 hash 생성 c.. 2025. 5. 19.
[DSA][Array & Hashing] 04. Group Anagrams LeetCode 49 04. Group AnagramsGiven an array of strings strs, group the anagrams together. You can return the answer in any order. [질문하기]- 배열의 길이와 문자열의 길이는 최대 몇인가요?- 그룹 간의 출력 순서도 고려해야 하나요?- 배열의 문자열에 소문자/대문자가 혼합될 수 있나요? 알파벳이 아닌 문자가 포함될 수 있나요? [아이디어]Counter를 hashMap의 key로 사용해 버리자 [풀이 1] Hash with Sortingclass Solution: def groupAnagrams(self, strs: List[str]) -> List[List[str]]: hashM.. 2025. 5. 18.