지식/알고리즘
-
180일 (621. Task Scheduler) greedy지식/알고리즘 2024. 3. 19. 22:10
You are given an array of CPU tasks, each represented by letters A to Z, and a cooling time, n. Each cycle or interval allows the completion of one task. Tasks can be completed in any order, but there's a constraint: identical tasks must be separated by at least n intervals due to cooling time. Return the minimum number of intervals required to complete all tasks. Example 1: Input: tasks = ["A"..
-
179일 (217. Contains Duplicate) Set, 매우 쉬움지식/알고리즘 2024. 3. 18. 21:01
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1: Input: nums = [1,2,3,1] Output: true Example 2: Input: nums = [1,2,3,4] Output: false Example 3: Input: nums = [1,1,1,3,3,4,3,2,4,2] Output: true Constraints: 1
-
178일 (404. Sum of Left Leaves) DFS지식/알고리즘 2024. 3. 17. 12:55
Given the root of a binary tree, return the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of another node. Example 1: Input: root = [3,9,20,null,null,15,7] Output: 24 Explanation: There are two left leaves in the binary tree, with values 9 and 15 respectively. Example 2: Input: root = [1] Output: 0 Constraints: The number of nodes in the ..
-
177일 (CodeTestcaseTestcaseTest Result525. Contiguous Array) Map, 매우 어려움지식/알고리즘 2024. 3. 16. 17:13
Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1. Example 1: Input: nums = [0,1] Output: 2 Explanation: [0, 1] is the longest contiguous subarray with an equal number of 0 and 1. Example 2: Input: nums = [0,1,0] Output: 2 Explanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal number of 0 and 1. Constraints: 1
-
176일 (CodeTestcaseTestcaseTest Result238. Product of Array Except Self) Array지식/알고리즘 2024. 3. 15. 13:52
Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer. You must write an algorithm that runs in O(n) time and without using the division operation. Example 1: Input: nums = [1,2,3,4] Output: [24,12,8,6] Example 2: Input: nums =..
-
175일 (CodeTestcaseTestcaseTest Result930. Binary Subarrays With Sum) Prefix Sum지식/알고리즘 2024. 3. 14. 12:52
Given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal. A subarray is a contiguous part of the array. Example 1: Input: nums = [1,0,1,0,1], goal = 2 Output: 4 Explanation: The 4 subarrays are bolded and underlined below: [1,0,1,0,1] [1,0,1,0,1] [1,0,1,0,1] [1,0,1,0,1] Example 2: Input: nums = [0,0,0,0,0], goal = 0 Output: 15 Constraints: 1
-
174일 (CodeTestcaseTestcaseTest Result2485. Find the Pivot Integer) Pointers, 쉬움지식/알고리즘 2024. 3. 13. 12:12
Given a positive integer n, find the pivot integer x such that: The sum of all elements between 1 and x inclusively equals the sum of all elements between x and n inclusively. Return the pivot integer x. If no such integer exists, return -1. It is guaranteed that there will be at most one pivot index for the given input. Example 1: Input: n = 8 Output: 6 Explanation: 6 is the pivot integer since..