본문 바로가기

LeetCode/Array & Hashing42

[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.
[LeetCode][Kotlin] 706. Design HashMap 706. Design HashMapDesign a HashMap without using any built-in hash table libraries. Implement the MyHashMap class:MyHashMap() initializes the object with an empty map.void put(int key, int value) inserts a (key, value) pair into the HashMap. If the key already exists in the map, update the corresponding value.int get(int key) returns the value to which the specified key is mapped, or -1 if this.. 2024. 8. 16.
[LeetCode][Kotlin] 705. Design HashSet 705. Design HashSetDesign a HashSet without using any built-in hash table libraries. Implement MyHashSet class:void add(key) Inserts the value key into the HashSet.bool contains(key) Returns whether the value key exists in the HashSet or not.void remove(key) Removes the value key in the HashSet. If key does not exist in the HashSet, do nothing.내장된 해시 테이블 라이브러리를 사용하지 않고 HashSet을 디자인합니다.MyHashSet .. 2024. 8. 16.
[LeetCode][Kotlin] 448. Find All Numbers Disappeared in an Array 448. Find All Numbers Disappeared in an ArrayGiven an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.nums[i]가 [1, n] 범위에 있는 n개의 정수로 구성된 배열이 주어지면, nums에 나타나지 않는 [1, n] 범위의 모든 정수 배열을 반환합니다. Example 1:Input: nums = [4,3,2,7,8,2,3,1]Output: [5,6] Example 2:Input: nums = [1,1]Output: [2] Constraints:n =.. 2024. 8. 16.