3/24 풀이
·
Algorithm/Leetcode
https://leetcode.com/problems/count-the-number-of-complete-components/description/?envType=daily-question&envId=2025-03-22 2685. Count the Number of Complete Components   그래프를 순회하면서, 연결된 그래프인 경우에만 결과값을 더해주는 문제였다.나름 쉽다고 생각해서 접근했지만, 생각보다 벽에 막혔다. 처음에 사이클을 판별하는 DFS를 통해서 문제 접근을 했지만, 3-4나 5와 같은 그래프 형태도 연결된 그래프로 가정했기 때문에 틀렸다. 다른 사람의 풀이를 참고해서야 힌트를 얻을 수 있었는데, 매번 DFS를 순회할 때 마다 각 노드 번호를 리스트에 삽입해준다.예를 들어서 0..
2467. Most Profitable Path in a Tree
·
Algorithm/Leetcode
https://leetcode.com/problems/most-profitable-path-in-a-tree/description/  문제 이해문제에서 요구하는 바는 이렇다.Alice는 노드 0에서 출발해서, 리프 노드까지 도달한다.Bob은 주어진 노드에서 출발해서, 노드 0까지 도달한다.이 과정 속에서, Alice가 가질 수 있는 최대 보상 값을 구하는 문제였다. 우선, 보상 값을 구할 때 세가지 다른 케이스가 존재했다.Alice가 해당 노드에 먼저 도착한 경우: 해당 보상을 그대로 얻는다.Bob이 먼저 해당 노드에 도착한 경우: 보상을 획득하지 못한다.둘이 동시에 도착한 경우: 현재 보상 / 2를 얻는다.이러한 문제 흐름을 먼저 해결하기 위해선, Bob이 각 노드에 도착하는 시간을 먼저 계산해줘야 했..
1910. Remove All Occurrences of a Substring
·
Algorithm/Leetcode
https://leetcode.com/problems/remove-all-occurrences-of-a-substring/description/?envType=daily-question&envId=2025-02-11 Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed:Find the leftmost occurrence of the substring part and remove it from s.Return s after removing all occurrences of part.A substring is a contiguous sequen..
1834. Single-Threaded CPU
·
Algorithm/Leetcode
https://leetcode.com/problems/single-threaded-cpu/
2381. Shifting Letters II
·
Algorithm/Leetcode
https://leetcode.com/problems/shifting-letters-ii/description/?envType=daily-question&envId=2025-01-05     shift = [0, 0, 0]이 주어질 때, shift[0]과 shift[1]은 시작 인덱스와 끝 인덱스고, shift[2]는 움직이는 방향을 정해준다.1인 경우엔, 'a' -> 'b'와 같이 옮겨주고0인 경우엔 'b' -> 'a'와 같이 뒤로 한칸 이동한다. 이 문제 역시도 constraints 조건으로 인해서 시간복잡도를 O(N^2) 미만으로 줄여야했다. 그래서 이전 문제와 비슷하게 누적합, 차분 배열을 사용한 방식으로 해결했다. 이전 문제와 살짝 다른 부분은 1인 경우엔 시작점++, 끝점-- 라면,0인 경우엔..
1589. Maximum Sum Obtained of Any Permutation
·
Algorithm/Leetcode
We have an array of integers, nums, and an array of requests where requests[i] = [starti, endi]. The ith request asks for the sum of nums[starti] + nums[starti + 1] + ... + nums[endi - 1] + nums[endi]. Both starti and endi are 0-indexed.Return the maximum total sum of all requests among all permutations of nums.Since the answer may be too large, return it modulo 109 + 7. Example 1:Input: nums = ..
2661. First Completely Painted Row or Column
·
Algorithm/Leetcode
https://leetcode.com/problems/first-completely-painted-row-or-column/description/?envType=daily-question&envId=2025-01-20 You are given a 0-indexed integer array arr, and an m x n integer matrix mat. arr and mat both contain all the integers in the range [1, m * n].Go through each index i in arr starting from index 0 and paint the cell in mat containing the integer arr[i].Return the smallest ind..
백트래킹 문제들
·
Algorithm/Leetcode
79. Word Search https://leetcode.com/problems/word-search/description/?envType=problem-list-v2&envId=backtracking 2차원 배열을 순회하면서 word로 주어진 값을 만들 수 있는지 판단하는 문제였다.현재 좌표에서 동서남북, 4방향으로 이동하는 것도 염두에 둬야 했던 문제였다. 39. Combination Sumhttps://leetcode.com/problems/combination-sum/description/ Input: candidates = [2,3,6,7], target = 7 Output: [[2,2,3],[7]] Explanation: 2 and 3 are candidates, and 2 + 2 + 3 =..
934. Shortest Bridge
·
Algorithm/Leetcode
https://leetcode.com/problems/shortest-bridge/description/ You are given an n x n binary matrix grid where 1 represents land and 0 represents water.An island is a 4-directionally connected group of 1's not connected to any other 1's. There are exactly two islands in grid.You may change 0's to 1's to connect the two islands to form one island.Return the smallest number of 0's you must flip to con..
3223. Minimum Length of String After Operations
·
Algorithm/Leetcode
https://leetcode.com/problems/minimum-length-of-string-after-operations/description/?envType=daily-question&envId=2025-01-13 You are given a string s.You can perform the following process on s any number of times:Choose an index i in the string such that there is at least one character to the left of index i that is equal to s[i], and at least one character to the right that is also equal to s[i..