본문 바로가기

LeetCode74

[LeetCode][Kotlin] 907. Sum of Subarray Minimums 907. Sum of Subarray MinimumsGiven an array of integers arr, find the sum of min(b), where b ranges over every (contiguous) subarray of arr. Since the answer may be large, return the answer modulo 10^9 + 7.정수 arr의 배열이 주어졌을 때, b가 arr의 모든 (인접한) 부분 배열에 걸쳐 있는 min(b)의 합을 구하세요. 답이 클 수 있으므로 답을 10^9 + 7로 나눈 나머지로 반환합니다. Example 1:Input: arr = [3,1,2,4]Output: 17Explanation: Subarrays are [3], [1], [2], [.. 2024. 12. 3.
[LeetCode][Kotlin] 456. 132 Pattern 456. 132 PatternGiven an array of n integers nums, a 132 pattern is a subsequence of three integers nums[i], nums[j] and nums[k] such that i  Return true if there is a 132 pattern in nums, otherwise, return false.n개의 정수 nums의 배열이 주어지면 132 패턴은 i nums에 132 패턴이 있으면 true를 반환하고, 그렇지 않으면 false를 반환합니다. Example 1:Input: nums = [1,2,3,4]Output: falseExplanation: There is no 132 pattern in the sequence. E.. 2024. 12. 3.
[LeetCode][Kotlin] 1209. Remove All Adjacent Duplicates in String II 1209. Remove All Adjacent Duplicates in String IIYou are given a string s and an integer k, a k duplicate removal consists of choosing k adjacent and equal letters from s and removing them, causing the left and the right side of the deleted substring to concatenate together. We repeatedly make k duplicate removals on s until we no longer can. Return the final string after all such duplicate remo.. 2024. 12. 2.
[LeetCode][Kotlin] 402. Remove K Digits 402. Remove K DigitsGiven string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.음이 아닌 정수 num을 나타내는 문자열 num과 정수 k가 주어지면, num에서 k자리를 제거한 후 가능한 가장 작은 정수를 반환합니다. Example 1:Input: num = "1432219", k = 3Output: "1219"Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest. E.. 2024. 12. 2.
[LeetCode][Kotlin] 853. Car Fleet 853. Car FleetThere are n cars at given miles away from the starting mile 0, traveling to reach the mile target. You are given two integer array position and speed, both of length n, where position[i] is the starting mile of the ith car and speed[i] is the speed of the ith car in miles per hour. A car cannot pass another car, but it can catch up and then travel next to it at the speed of the slo.. 2024. 11. 29.
[LeetCode][Kotlin] 735. Asteroid Collision 735. Asteroid CollisionWe are given an array asteroids of integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the same speed. Find out the state of the asteroids after all collisions. If two asteroids meet, the smaller one will explode. If.. 2024. 11. 29.
[LeetCode][Kotlin] 22. Generate Parentheses 22. Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.n쌍의 괄호가 주어졌을 때, 올바르게 구성된 괄호의 모든 조합을 생성하는 함수를 작성하세요. Example 1:Input: n = 3Output: ["((()))","(()())","(())()","()(())","()()()"] Example 2:Input: n = 1Output: ["()"] Constraints:1 코드 1class Solution { fun generateParenthesis(n: Int): List { val stack = mutableL.. 2024. 11. 28.