분류 전체보기
-
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..
-
99클럽(2기) - 코테스터디 15일차 TIL # GraphAlgorithm 2024. 6. 12. 20:57
LeetCode - 1791. Find Center of Star Graph There is an undirected star graph consisting of n nodes labeled from 1 to n. A star graph is a graph where there is one center node and exactly n - 1 edges that connect the center node with every other node.You are given a 2D integer array edges where each edges[i] = [ui, vi] indicates that there is an edge between the nodes ui and vi. Return the center..
-
99클럽(2기) - 코테스터디 14일차 TIL # Binary SearchAlgorithm 2024. 6. 11. 20:42
LeetCode - 1351. Count Negative Numbers in a Sorted MatrixGiven a m x n matrix grid which is sorted in non-increasing order both row-wise and column-wise, return the number of negative numbers in grid.Constraints:m == grid.lengthn == grid[i].length1 -100 1. 첫 번째 풀이 풀이는 20분 정도 걸렸지만이중 반복문으로 모든 행과 열을 순회하기 때문에 시간 복잡도가 O(m * n)이다. 모든 행은 다 탐색하더라도 열에 대해서는 이분 탐색을 적용할 수 있을 것 같았지만 해결책이 쉽게 떠오르지 않았다. 1) 행렬..
-
99클럽(2기) - 코테스터디 13일차 TIL # Binary SearchAlgorithm 2024. 6. 11. 00:32
LeetCode - 35. Search In Position Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You must write an algorithm with O(log n) runtime complexity.Constraints1 -104 nums contains distinct values sorted in ascending order.-104 1. 첫 번째 풀이 원래는 풀이 과정을 머릿속으로 그려보고 답을 낼 수 있을 것 같다는..
-
99클럽(2기) - 코테스터디 12일차 TIL # Dynamic ProgrammingAlgorithm 2024. 6. 10. 10:42
LeetCode - 1025. Divisor Game Alice and Bob take turns playing a game, with Alice starting first. Initially, there is a number n on the chalkboard. On each player's turn, that player makes a move consisting of:Choosing any x with 0 and n % x == 0.Replacing the number n on the chalkboard with n - x.Also, if a player cannot make a move, they lose the game.Return true if and only if Alice wins the..
-
99클럽(2기) - 코테스터디 11일차 TIL # Dynamic ProgrammingAlgorithm 2024. 6. 7. 20:56
LeetCode - 118. Pascal's TriangleGiven an integer numRows, return the first numRows of Pascal's triangle.In Pascal's triangle, each number is the sum of the two numbers directly above it as shown: 1. 나의 첫 번째 풀이 동적 계획법을 풀기 위해 반복적으로 등장하는 동일한 패턴을 찾으려고 했다. 현재 행의 현재 열에 들어갈 데이터는 이전 행의 '현재 열 - 1인 인덱스'를 가지는 데이터의 값과 이전 행의 '현재 열과 동일한 인덱스'를 가지는 데이터의 값을 합친 값이라는 패턴을 발견했다. 즉, 현재 위치의 값은 바로 윗 줄의 양쪽 대각선 방향으로 인접한..