전체 글
-
99클럽(2기) - 코테스터디 23일차 TIL # Array카테고리 없음 2024. 6. 22. 10:48
LeetCode - 2089. Find Target Indices After Sorting ArrayYou are given a 0-indexed integer array nums and a target element target.A target index is an index i such that nums[i] == target.Return a list of the target indices of nums after sorting nums in non-decreasing order. If there are no target indices, return an empty list. The returned list must be sorted in increasing order. 1. 첫 번째 풀이 답을 반환..
-
99클럽(2기) - 코테스터디 22일차 TIL # StringAlgorithm 2024. 6. 20. 10:50
LeetCode - Decode the MessageYou are given the strings key and message, which represent a cipher key and a secret message, respectively. The steps to decode message are as follows:Use the first appearance of all 26 lowercase English letters in key as the order of the substitution table.Align the substitution table with the regular English alphabet.Each letter in message is then substituted using..
-
99클럽(2기) - 코테스터디 21일차 TIL # Array # StringAlgorithm 2024. 6. 18. 23:21
LeetCode - 1528. Shuffle StringYou are given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string.Return the shuffled string. 1. 첫 번째 풀이1) s를 구성하는 글자의 인덱스와 해당 글자를 담을 딕셔너리 strings 생성 defaultdict를 이용해 s를 구성하는 글자의 인덱스를 키로, 해당 글자를 값으로 갖는 딕셔너리 strings를 생성한다. 2) s를 순회하며 indices[i..
-
99클럽(2기) - 코테스터디 20일차 TIL # ArrayAlgorithm 2024. 6. 18. 09:24
LeetCode - 1773. Count Items Matching a RuleYou are given an array items, where each items[i] = [typei, colori, namei] describes the type, color, and name of the ith item. You are also given a rule represented by two strings, ruleKey and ruleValue. Example 1:Input: items = [["phone","blue","pixel"],["computer","silver","lenovo"],["phone","gold","iphone"]], ruleKey = "color", ruleValue = "silver"..
-
99클럽(2기) - 코테스터디 19일차 TIL # 완전 탐색Algorithm 2024. 6. 17. 05:54
LeetCode - 2942. Find Words Containing CharacterYou are given a 0-indexed array of strings words and a character x.Return an array of indices representing the words that contain the character x.Note that the returned array may be in any order. 1. 첫 번째 풀이 리스트 컴프리핸션을 이용해 한 줄로 풀었다. enumerate 함수를 사용해서 words의 인덱스 idx와 요소 word를 반복문으로 순회하며 x가 word 안에 포함되어 있으면 해당 인덱스를 추가한 리스트를 반환한다. from typing import L..
-
99클럽(2기) - 코테스터디 18일차 TIL # ArrayAlgorithm 2024. 6. 15. 11:39
LeetCode - 1512. Number of Good PairsGiven an array of integers nums, return the number of good pairs.A pair (i, j) is called good if nums[i] == nums[j] and i j. 1. 나의 풀이 nums에 대한 인덱스 i, j를 구하기 위해 이중반복문을 사용했다. 시간복잡도 O(n^2)이다. 1) good_pairs_list 초기화 'nums[i] == nums[j] and i 2) nums를 순회해서 good_pairs_list 갱신 nums의 i번째 인덱스는 0에서 len(nums) - 1까지 순방향으로 진행하고 j번째 인덱스는 모든 i번째 인덱스에 대해 len(nums) - 1에서 ..
-
99클럽(2기) - 코테스터디 17일차 TIL # ArrayAlgorithm 2024. 6. 15. 10:41
LeetCode - 1470.Suffle the ArrayGiven the array nums consisting of 2n elements in the form [x1,x2,...,xn,y1,y2,...,yn].Return the array in the form [x1,y1,x2,y2,...,xn,yn]. 1. 첫 번째 풀이1) 리스트 초기화 answer에 빈 리스트를 할당한다. 2) 0부터 n까지의 범위 순회 nums의 i번째 요소와 nums의 i + n번째 요소를 순서대로 더해준다. 3) 최종 리스트 반환 from typing import Listclass Solution: def shuffle(self, nums: List[int], n: int) -> List[int]: an..
-
99클럽(2기) - 코테스터디 16일차 TIL # GraphAlgorithm 2024. 6. 13. 21:16
LeetCode - 2037. Minimum Number of Moves to Seat Everyone There are n seats and n students in a room. You are given an array seats of length n, where seats[i] is the position of the ith seat. You are also given the array students of length n, where students[j] is the position of the jth student.You may perform the following move any number of times:Increase or decrease the position of the ith st..