LeetCode
-
99클럽 코테 스터디 8일차 TIL: 배열, 1286. Iterator for CombinationToday_I_Learned/Algorithm 2024. 6. 18. 00:21
문제https://leetcode.com/problems/iterator-for-combination/description/ 통과 여부Fail 나의 접근법 Backtrack 을 이용하여 CombinationIterator 생성자 호출 시 conbinationLength 길이만큼의 가능한 모든 조합을 미리 구하여 멤버 필드로 저장한다.next() 와 hasNext() 문자열 조합 멤버 필드로부터 요소를 하나씩 가져와 return 한다.
-
99클럽 코테 스터디 7일차 TIL: 배열, 1282. Group the People Given the Group Size They Belong ToToday_I_Learned/Algorithm 2024. 6. 17. 00:06
문제https://leetcode.com/problems/group-the-people-given-the-group-size-they-belong-to/description/ 통과 여부Pass 나의 접근법 2차원 List 인 tmp 를 생성한다.groupSizes 를 순회하며 'groupSizes 의 값 -> tmp 의 Index 가 되는 요소(List)에 groupSizes 의 인덱스 번호를 추가' 를 반복한다.tmp 를 순회하며 각 요소 배열을 인덱스 번호의 길이로 나눈다.class Solution: def groupThePeople(self, groupSizes: List[int]) -> List[List[int]]: answer = [] tmp = [[] for _ ..
-
99클럽 코테 스터디 6일차 TIL: 배열, LeetCode 2433. Find The Original Array of Prefix XorToday_I_Learned/Algorithm 2024. 6. 16. 09:45
문제https://leetcode.com/problems/find-the-original-array-of-prefix-xor/description/ 통과 여부Pass 나의 접근법 XOR 연산자의 특성을 알고 있으면 쉽게 풀 수 있는 문제 ( A ^ B = C 일 때, A ^ C = B )하지만 나는 ^ (XOR 연산자) 를 몰라 검색 시간이 필요했다.class Solution: def findArray(self, pref: List[int]) -> List[int]: arr = [pref[0]] for i in range(1, len(pref)): arr.append(pref[i]^pref[i-1]) return arr
-
99클럽 코테 스터디 5일차 TIL: 배열, Leetcode 1476. Subrectangle QueriesToday_I_Learned/Algorithm 2024. 6. 15. 10:43
문제https://leetcode.com/problems/subrectangle-queries/description/ 통과 여부Pass 나의 접근법 문제만 이해되면 풀이는 특별할 것 없이 단순했던 문제.두 번째 Input 의 0번 요소로 2차원 List 인 self.rectangle 을 초기화updateSubrectangle(row1, col1, row2, col2, newValue) 는 2 중 for문을 돌려 self.rectangle[row1][col1] 부터 self.rectangle[row2][col2] 까지 newValue 로 초기화문제는 해결되었지만, 코테가 이렇게 쉬울리 없다는 이상한 의심이 들어 더 빠른 방법이 있는 지 재도전 해 볼 예정이다.class SubrectangleQueries:..