Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- greedy
- Counting
- Tree
- hash table
- geometry
- SQL
- sorting
- database
- bit manipulation
- Number Theory
- Stack
- implement
- two pointers
- 구현
- 자바
- Data Structure
- Binary Tree
- dynamic programming
- array
- 코테
- 파이썬
- java
- Math
- simulation
- Binary Search
- Matrix
- Method
- string
- 코딩테스트
- Class
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 506. Relative Ranks 본문
1. Input
1) int[] score
2. Output
1) 각 점수에 대해서 등수를 매긴 string[]을 반환
- 1등은 “Gold Medal"
- 2등은 "Silver Medal"
- 3등은 “Bronze Medal"
- x등은 “x"
3. Constraint
1) n == score.length
2) 1 <= n <= 10^4
3) 0 <= score[i] <= 10^6
4) score에 중복되는 점수는 없다.
4. Example
Input: score = [5,4,3,2,1] -> Output: ["Gold Medal","Silver Medal","Bronze Medal","4","5"]
5. Code
1) 첫 코드(2023/05/23)
class Solution {
public String[] findRelativeRanks(int[] score) {
String[] ans = new String[score.length];
List<Integer> list = new ArrayList<>();
for(int i : score)
list.add(i);
Arrays.sort(score);
for(int i=score.length-1 ; i>=0 ; i--){
int rank = score.length-i;
if(rank>3)
ans[list.indexOf(score[i])] = String.valueOf(rank);
else if(rank==1)
ans[list.indexOf(score[i])] = "Gold Medal";
else if(rank==2)
ans[list.indexOf(score[i])] = "Silver Medal";
else
ans[list.indexOf(score[i])] = "Bronze Medal";
}
return ans;
}
}
- 시간도 공간도 beat%가 다 5%인데, 당장은 생각이 나지 않는다.
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[백준 온라인 저지] 1181. 단어 정렬 (0) | 2023.05.24 |
---|---|
[LeetCode/Easy] 530. Minimum Absolute Difference in BST (0) | 2023.05.23 |
[백준 온라인 저지] 2752. 세수정렬 (0) | 2023.05.20 |
[LeetCode/Easy] 485. Max Consecutive Ones (0) | 2023.05.19 |
[LeetCode/Easy] 482. License Key Formatting (0) | 2023.05.19 |