전체 글
-
99클럽 코테 스터디 13일차 TIL: 스택/큐, Leetcode 1823. Find the Winner of the Circular GameToday_I_Learned/Algorithm 2024. 6. 22. 18:32
문제https://leetcode.com/problems/find-the-winner-of-the-circular-game/description/ 통과 여부Pass 나의 접근법 1 부터 n 까지 구성된 List 'q' 생성매 Turn 마다 k 번째에 있는 요소 탐색 => target = k % len(q) (만약 index 가 0부터 시작이면 -1 을 해주어야 함.)매 Turn 마다 target 을 제거하고 q 를 갱신. q = 'target 이후의 List' + 'target 이전까지의 List'q 의 길이가 1이 될 때까지 반복class Solution: def findTheWinner(self, n: int, k: int) -> int: q = [e+1 for e ..
-
99클럽 코테 스터디 12일차 TIL: 정렬, Leetcode 869. Reordered Power of 2Today_I_Learned/Algorithm 2024. 6. 21. 21:10
문제https://leetcode.com/problems/reordered-power-of-2/description/ 통과 여부Fail 나의 접근법 주어진 숫자를 재조합하는 문제였으므로 당연히 순열을 사용해 풀어야한다고 생각했다.먼저 끝자리가 짝수로 끝나는 수열을 모두 구한 후 2의 거듭제곱인지를 확인하는 것이었다. (2의 거듭제곱인지 확인하는 방법: https://hkim-data.tistory.com/179)그러나 순열을 구현하는 방법을 몰랐던 나는 결국 컨닝을 하게 되었는데 순열을 사용하지 않는 신박한 방법이 있었다.바로 2의 거듭제곱 수에 사용된 숫자들의 빈도수와 주어진 정수를 이루는 숫자들의 빈도수가 일치하는 지 확인하는 것이다.(!!!) https://81shinez.tistory.com/27..
-
99클럽 코테 스터디 11일차 TIL: 배열, Leetcode 347. Top K Frequent ElementsToday_I_Learned/Algorithm 2024. 6. 20. 23:00
문제https://leetcode.com/problems/top-k-frequent-elements/description/ 통과 여부Fail -> Pass 나의 접근법 num 를 순회하며 각 element 의 count 를 별도의 dict 에 count:[num,..] 으로 저장dict 의 key 로 정렬하려 앞에서부터 k까지의 key 에 속하는 value(숫자) 를 Return ... 이라는 거창한 계획을 세웠었는데항해 정규 스터디 시간을 통해 python 의 collections 에서 most_common() 이라는 함수를 제공하고 있다는 사실을 알게 되었다. 이 함수를 사용하면 1 줄 coding 이 가능해진다!!!python 을 이런 utility 함수들이 많이 제공되고 있다보니 배열같은 문제에..
-
99클럽 코테 스터디 10일차 TIL: 배열, Leetcode 451. Sort Characters By FrequencyToday_I_Learned/Algorithm 2024. 6. 19. 20:08
문제https://leetcode.com/problems/sort-characters-by-frequency/description/ 통과 여부Pass 나의 접근법 첫 번째 방법class Solution: def frequencySort(self, s: str) -> str: # 문자 - 빈도수로 dict 초기화 : 중복되는 문자 제거 char_frq = {} for ch in s: if ch in char_frq: char_frq[ch] += 1 else: char_frq[ch] = 1 # (빈도수, 문자) 쌍을 갖는 배열을 빈도..
-
99클럽 코테 스터디 9일차 TIL: 배열, 1529. Minimum Suffix FlipsToday_I_Learned/Algorithm 2024. 6. 19. 00:11
문제https://leetcode.com/problems/minimum-suffix-flips/description/ 통과 여부Fail 나의 접근법 XOR 문제는 풀이 경험 부족 탓에 접근법에 대한 감이 1도 없었다. 하여 다른 사람들이 정리한 글들을 참고하였다.참고: https://blog.naver.com/PostView.naver?blogId=babobigi&logNo=222042107759&parentCategoryNo=&categoryNo=30&viewDate=&isShowPopularPosts=false&from=postView LeetCode) 1529. Bulb Switcher IV문제 https://leetcode.com/contest/weekly-contest-199/problems/b..
-
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