본문 바로가기

leetcode73

[LeetCode][Kotlin] 28. Find the Index of the First Occurrence in a String 28. Find the Index of the First Occurrence in a StringGiven two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.needle과 haystack이라는 두 문자열이 주어지면 haystack에서 needle이 처음 나타나는 인덱스를 반환하거나, needle이 haystack의 일부가 아닌 경우 -1을 반환합니다. Example 1:Input: haystack = "sadbutsad", needle = "sad"Output: 0Explanation: "sad" occurs a.. 2024. 8. 29.
[LeetCode][Kotlin] 2002. Maximum Product of the Length of Two Palindromic Subsequences 2002. Maximum Product of the Length of Two Palindromic SubsequencesGiven a string s, find two disjoint palindromic subsequences of s such that the product of their lengths is maximized. The two subsequences are disjoint if they do not both pick a character at the same index. Return the maximum possible product of the lengths of the two palindromic subsequences. A subsequence is a string that can.. 2024. 8. 28.
[LeetCode][Kotlin] 1963. Minimum Number of Swaps to Make the String Balanced 1963. Minimum Number of Swaps to Make the String BalancedYou are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'.A string is called balanced if and only if:It is the empty string, orIt can be written as AB, where both A and B are balanced strings, orIt can be written as [C], where C is a balanced string.You may.. 2024. 8. 28.
[LeetCode][Kotlin] 1930. Unique Length-3 Palindromic Subsequences 1930. Unique Length-3 Palindromic SubsequencesGiven a string s, return the number of unique palindromes of length three that are a subsequence of s. Note that even if there are multiple ways to obtain the same subsequence, it is still only counted once. A palindrome is a string that reads the same forwards and backwards. A subsequence of a string is a new string generated from the original strin.. 2024. 8. 28.
[LeetCode][Kotlin] 347. Top K Frequent Elements 347. Top K Frequent ElementsGiven an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order.정수 배열 nums와 정수 k가 주어지면 가장 자주 사용되는 k개의 요소를 반환합니다. 어떤 순서로든 답변을 반환할 수 있습니다. Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2] Example 2:Input: nums = [1], k = 1Output: [1] Constraints:1 -10^4 k is in the range [1, the number of unique elements.. 2024. 8. 27.
[LeetCode][Kotlin] 2073. Time Needed to Buy Tickets 2073. Time Needed to Buy TicketsThere are n people in a line queuing to buy tickets, where the 0th person is at the front of the line and the (n - 1)th person is at the back of the line. You are given a 0-indexed integer array tickets of length n where the number of tickets that the ith person would like to buy is tickets[i]. Each person takes exactly 1 second to buy a ticket. A person can only .. 2024. 8. 21.
[LeetCode][Kotlin] 1758. Minimum Changes To Make Alternating Binary String 1758. Minimum Changes To Make Alternating Binary StringYou are given a string s consisting only of the characters '0' and '1'. In one operation, you can change any '0' to '1' or vice versa. The string is called alternating if no two adjacent characters are equal. For example, the string "010" is alternating, while the string "0100" is not. Return the minimum number of operations needed to make s.. 2024. 8. 20.