Skip to content

Commit f45025b

Browse files
authored
Create 1985-find-the-kth-largest-integer-in-the-array.js
1 parent db64a15 commit f45025b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Sorting
3+
* Time O(n*log(n)) | Space O(1)
4+
* https://leetcode.com/problems/find-the-kth-largest-integer-in-the-array/
5+
* @param {string[]} nums
6+
* @param {number} k
7+
* @return {string}
8+
*/
9+
var kthLargestNumber = function(nums, k) {
10+
11+
// sort it string wise.
12+
nums.sort((a,b) => {
13+
if(a.length !== b.length) return b.length - a.length;
14+
return b.localeCompare(a);
15+
});
16+
17+
return nums[k-1];
18+
};

0 commit comments

Comments
 (0)