728x90
반응형
1. 옷가게 할인받기
class Solution {
public int solution(int price) {
int answer = 0;
if( price >= 100000 && price < 300000){
answer = (int) (price - (price * 0.05));
} else if( price >= 300000 && price < 500000){
answer = (int) (price - (price * 0.1));
} else if(price >= 500000){
answer = (int) (price - (price * 0.2));
} else {
answer = price;
}
return answer;
}
}
2. 아이스 아메리카노
class Solution {
public int[] solution(int money) {
int[] result = new int[2];
result[0] = money / 5500;
result[1] = money % 5500;
return result;
}
}
3. 나이 출력
class Solution {
public int solution(int age) {
return (2022 - age) + 1;
}
}
4. 배열 뒤집기
class Solution {
public int[] solution(int[] num_list) {
int[] answer = new int[num_list.length];
for(int i=0; i<num_list.length; i++){
answer[i] = num_list[num_list.length - 1 - i];
}
return answer;
}
}
728x90
반응형
'study_IT > 알고리즘 노트' 카테고리의 다른 글
[programmers] 코딩테스트 입문 Day 6 (0) | 2023.10.22 |
---|---|
[programmers] Lv2. 최댓값과 최솟값 (0) | 2023.10.20 |
[programmers] 코딩테스트 입문 Day 4 (0) | 2023.10.16 |
알고리즘 복잡도 (Complexity) (0) | 2023.10.14 |
[programmers] 코딩테스트 입문 Day 3 (0) | 2023.10.12 |