Notice
Hot Posts
Recent Posts
Recent Comments
반응형
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- BOJ
- 카카오
- 마곡속눈썹연장
- 등촌동속눈썹연장
- 직무면접
- 알고리즘
- 프로그래머스
- 딥러닝
- 코딩테스트
- 추석트래픽
- 포스코
- 삼성 SW역량테스트 기출
- 수학
- 리트코드
- 마곡속눈썹펌
- ai/bigdata
- 투포인터
- level2
- OS
- 백준
- 운영체제
- Java
- 정렬
- 1차면접
- leetcode
- 다시보기
- 시뮬레이션
- 삼성SW역량테스트
- 삼성
- 등촌동속눈썹펌
Archives
- Today
- Total
기록하는 습관을 들이자
[ leetcode ] Kth Largest Element in an Array 본문
반응형
문제
leetcode.com/problems/kth-largest-element-in-an-array/
Kth Largest Element in an Array - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
문제 풀이
리트코드 문제 난이도는 Medium에 해당하는데 개인적으로 가장 기초적인 문제라고 생각한다. 배열을 라이브러리를 사용해서 정렬만 해주면 간단하게 풀리는 문제이다.
나의 경우에는 자바를 이용하여 문제를 풀었기 때문에 nums 배열을 Arrays 라이브러리에 내장된 sort 메소드를 사용하여 오름차순 정렬을 해준 뒤 k번째로 큰 수를 리턴해주면 바로 끝!
코드
class Solution {
public int findKthLargest(int[] nums, int k) {
Arrays.sort(nums);
return nums[nums.length-k];
}
}
반응형
'알고리즘 > Leetcode' 카테고리의 다른 글
[ leetcode ] Valid Parentheses (0) | 2021.01.20 |
---|---|
[ leetcode ] Get Maximum in Generated Array (0) | 2021.01.18 |
[ leetcode ] The kth Factor of n (0) | 2021.01.06 |
[ leetcode ] Increasing Order Search Tree (0) | 2021.01.05 |
Comments