본문 바로가기

LeetCode/Two Pointers11

[LeetCod][Kotlin] 948. Bag of Tokens 948. Bag of TokensYou start with an initial power of power, an initial score of 0, and a bag of tokens given as an integer array tokens, where each tokens[i] denotes the value of tokeni. Your goal is to maximize the total score by strategically playing these tokens. In one move, you can play an unplayed token in one of the two ways (but not both for the same token):Face-up: If your current power.. 2024. 11. 14.
[LeetCode][Kotlin] 42. Trapping Rain Water 42. Trapping Rain WaterGiven n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining.너비가 1인 고도 지도를 나타내는 음이 아닌 정수 n개가 주어졌을 때, 비가 내린 후에 얼마나 많은 물을 가둘 수 있는지 계산하세요. Example 1:Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]Output: 6Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1.. 2024. 10. 21.
[LeetCode][Kotlin] 1578. Minimum Time to Make Rope Colorful 1578. Minimum Time to Make Rope ColorfulAlice has n balloons arranged on a rope. You are given a 0-indexed string colors where colors[i] is the color of the ith balloon. Alice wants the rope to be colorful. She does not want two consecutive balloons to be of the same color, so she asks Bob for help. Bob can remove some balloons from the rope to make it colorful. You are given a 0-indexed integer.. 2024. 10. 19.
[LeetCode][Kotlin] 779. K-th Symbol in Grammar 779. K-th Symbol in GrammarWe build a table of n rows (1-indexed). We start by writing 0 in the 1st row. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.For example, for n = 3, the 1st row is 0, the 2nd row is 01, and the 3rd row is 0110.Given two integer n and k, return the kth (1-indexed) symbol in the nth row .. 2024. 10. 19.
[LeetCode][Kotlin] 189. Rotate Array 189. Rotate ArrayGiven an integer array nums, rotate the array to the right by k steps, where k is non-negative.정수 배열 nums가 주어지면, 배열을 k 단계만큼 오른쪽으로 회전합니다. 여기서 k는 음수가 아닙니다. Example 1:Input: nums = [1,2,3,4,5,6,7], k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 steps to the right: [7,1,2,3,4,5,6]rotate 2 steps to the right: [6,7,1,2,3,4,5]rotate 3 steps to the right: [5,6,7,1,2,3,4] Example 2:Inp.. 2024. 10. 19.
[LeetCode][Kotlin] 1498. Number of Subsequences That Satisfy the Given Sum Condition 1498. Number of Subsequences That Satisfy the Given Sum ConditionYou are given an array of integers nums and an integer target. Return the number of non-empty subsequences of nums such that the sum of the minimum and maximum element on it is less or equal to target. Since the answer may be too large, return it modulo 109 + 7.정수 nums와 정수 target의 배열이 주어집니다. nums의 비어 있지 않은 부분 시퀀스의 개수를 반환합니다. 이 부분 시.. 2024. 10. 19.
[LeetCode][Kotlin] 18. 4Sum 18. 4SumGiven an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that:0 a, b, c, and d are distinct.nums[a] + nums[b] + nums[c] + nums[d] == targetYou may return the answer in any order.n개의 정수로 구성된 배열 nums가 주어지면 다음과 같은 모든 고유한 사중항 [nums[a], nums[b], nums[c], nums[d]]의 배열을 반환합니다.- 0 - a, b, c, d는 서로 다릅니다. - nums[a] + nums[b] + nums[.. 2024. 10. 19.