스파르타코딩클럽
Day 25 TIL
글 잘 쓰는 독종
2024. 10. 24. 20:27
오늘 배운것
https://school.programmers.co.kr/learn/courses/30/lessons/12917
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
import java.util.*;
class Solution {
public String solution(String s) {
char[] chars = s.toCharArray();
Arrays.sort(chars);
String answer = new StringBuilder(new String(chars)).reverse().toString();
return answer;
}
}
StringBuilder 자주 써야겠다
https://school.programmers.co.kr/learn/courses/30/lessons/68935
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
class Solution {
public int solution(int n) {
String str = "";
while(n!=0){
str += n%3;
n /= 3;
}
return Integer.parseInt(str, 3);
}
}
Integer.parseInt의 사용법을 익혀야겠다.
https://school.programmers.co.kr/learn/courses/30/lessons/12930
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
class Solution {
public String solution(String s) {
String answer = "";
String[] str = s.split("");
int idx = 0;
for (int i=0; i< str.length; i++){
if(str[i].equals(" ")){
idx = 0;
} else if(idx % 2 == 0){
str[i] = str[i].toUpperCase();
idx++;
} else if(idx % 2 != 0) {
str[i] = str[i].toLowerCase();
idx++;
}
answer += str[i];
}
return answer;
}
}
split() 의 사용법을 잘 알아둬야겠다.
새싹반 강의 - 제네릭, 예외처리
https://school.programmers.co.kr/learn/courses/30/lessons/68644
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
import java.util.*;
class Solution {
public int[] solution(int[] numbers) {
int[] answer;
HashSet<Integer> set = new HashSet<>();
for(int i=0; i<numbers.length; i++){
for(int j=i+1; j<numbers.length; j++){
set.add(numbers[i]+numbers[j]);
}
}
answer = new int[set.size()];
int j = 0;
for(Integer s : set) {
answer[j++] = s;
}
Arrays.sort(answer);
return answer;
}
}
Hashset을 int array로 변환해서 정렬