본문 바로가기

LeetCode/Array & Hashing42

[LeetCode][Kotlin] 2405. Optimal Partition of String 2405. Optimal Partition of StringGiven a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than once. Return the minimum number of substrings in such a partition. Note that each character should belong to exactly one substring in a partition.문자열 s가 주어지면 각 부분 문자열의 문자가 고유하도록 문자열을 하.. 2024. 10. 19.
[LeetCode][Kotlin] 1396. Design Underground System 1396. Design Underground SystemAn underground railway system is keeping track of customer travel times between different stations. They are using this data to calculate the average time it takes to travel from one station to another. Implement the UndergroundSystem class:void checkIn(int id, string stationName, int t)A customer with a card ID equal to id, checks in at the station stationName at .. 2024. 10. 19.
[LeetCode][Kotlin] 1249. Minimum Remove to Make Valid Parentheses 1249. Minimum Remove to Make Valid ParenthesesGiven a string s of '(' , ')' and lowercase English characters.Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and return any valid string.Formally, a parentheses string is valid if and only if:It is the empty string, contains only lowercase characters, orIt c.. 2024. 10. 19.
[LeetCode][Kotlin] 2306. Naming a Company 2306. Naming a CompanyYou are given an array of strings ideas that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:Choose 2 distinct names from ideas, call them ideaA and ideaB.Swap the first letters of ideaA and ideaB with each other.If both of the new names are not found in the original ideas, then the name ideaA ideaB (th.. 2024. 10. 19.
[LeetCode][Kotlin] 451. Sort Characters By Frequency 451. Sort Characters By FrequencyGiven a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string. Return the sorted string. If there are multiple answers, return any of them.문자열 s가 주어지면 문자 빈도에 따라 내림차순으로 정렬합니다. 문자의 빈도는 해당 문자가 문자열에 나타나는 횟수입니다. 정렬된 문자열을 반환합니다. 답변이 여러 개인 경우 답변 중 하나를 반환하세요. Example 1:.. 2024. 10. 19.
[LeetCode][Kotlin] 1685. Sum of Absolute Differences in a Sorted Array 1685. Sum of Absolute Differences in a Sorted ArrayYou are given an integer array nums sorted in non-decreasing order. Build and return an integer array result with the same length as nums such that result[i] is equal to the summation of absolute differences between nums[i] and all the other elements in the array. In other words, result[i] is equal to sum(|nums[i]-nums[j]|) where 0 0-indexed).비내.. 2024. 10. 18.
[LeetCode][Kotlin] 2483. Minimum Penalty for a Shop 2483. Minimum Penalty for a ShopYou are given the customer visit log of a shop represented by a 0-indexed string customers consisting only of characters 'N' and 'Y':if the ith character is 'Y', it means that customers come at the ith hourwhereas 'N' indicates that no customers come at the ith hour.If the shop closes at the jth hour (0 penalty is calculated as follows:For every hour when the shop.. 2024. 10. 18.