This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given a 2D matrix, return the matrix transposed. | |
Note: The transpose of a matrix is an operation that flips each value in the matrix across its main diagonal. | |
Ex: Given the following matrix… | |
matrix = [ | |
[1, 2], | |
[3, 4] | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given an array of strings words and an integer k, return the k most frequent strings. | |
["i","love","leetcode","i","love","coding"], k = 2 | |
Output: ["i","love"] | |
* */ | |
fun topKFrequent(words: Array<String>, k: Int): List<String> { | |
return words.groupingBy { it }.eachCount() | |
.toList() | |
.sortedBy { (s, _) -> s } | |
.sortedByDescending { (_, v) -> v } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given an array of integers nums and an integer target, | |
return indices of the two numbers such that they add up to target. | |
Example: | |
Input: nums = [2,7,11,15], target = 9 | |
Output: [0,1] | |
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1]. | |
* */ | |
fun twoSum(nums: IntArray, target: Int): IntArray { | |
val map: MutableMap<Int, Int> = mutableMapOf() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given a list of strings, return a list of strings containing all anagrams grouped together. | |
strs = ["car", "arc", "bee", "eeb", "tea"], | |
return | |
[ | |
["car","arc"], | |
["tea"], | |
["bee","eeb"] | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given an integer n, return true if it is a power of three. Otherwise, return false. | |
An integer n is a power of three, if there exists an integer x such that n == 3x. | |
Example 1: | |
Input: n = 27 | |
Output: true | |
Example 2: | |
Input: n = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. | |
The relative order of the elements may be changed. | |
Since it is impossible to change the length of the array in some languages, | |
you must instead have the result be placed in the first part of the array nums. | |
More formally, if there are k elements after removing the duplicates, | |
then the first k elements of nums should hold the final result. | |
It does not matter what you leave beyond the first k elements. | |
Return k after placing the final result in the first k slots of nums. | |
Do not allocate extra space for another array. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given an array digits that represents a non-negative integer, add one to the number and return the result as an array. | |
Ex: Given the following digits... | |
digits = [1, 2], return [1, 3]. | |
Ex: Given the following digits... | |
digits = [9, 9], return [1, 0, 0]. | |
* */ | |
fun plusOne(digits: IntArray): IntArray { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given an array of intervals where intervals[i] = [starti, endi], | |
merge all overlapping intervals, | |
and return an array of the non-overlapping intervals that cover all the intervals in the input. | |
Example 1: | |
Input: intervals = [[1,3],[2,6],[8,10],[15,18]] | |
Output: [[1,6],[8,10],[15,18]] | |
Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6]. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given a reference to a linked list, return whether or not it forms a palindrome. | |
Ex: Given a reference to the following linked list... | |
head = 1->3->1, return true. | |
* */ | |
fun isPalindrome(head: ListNode?): Boolean { | |
var slow: ListNode? = head |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given two non-negative numbers, num1 and num2 represented as strings, sum the integers together and return the result as a string. | |
Ex: Given the following values for num1 and num2... | |
num1 = “2”, num2 = “5”, return “7”. | |
Ex: Given the following values for num1 and num2... | |
num1 = “7”, num2 = “95”, return “102”. | |
* */ |