Programmers/Java(14)
-
폰켓몬
문제 결과 풀이 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import java.util.*; class Solution { public int solution(int[] nums) { ArrayList phone = new ArrayList(); for(int i=0; i
2023.01.29 -
2016년
문제 결과 풀이 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 class Solution { public String solution(int a, int b) { String answer = ""; int[] months = {31,29,31,30,31,30,31,31,30,31,30,31}; int c = 0; for(int i=0; i
2023.01.29 -
두 개 뽑아서 더하기
문제 결과 풀이 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import java.util.*; class Solution { public Set solution(int[] numbers) { Set answer = new TreeSet(); for(int i=0; i
2023.01.29 -
문자열 내 p와 y의 개수
문제 결과 1 2 3 4 5 6 7 class Solution { boolean solution(String s) { s=s.toUpperCase(); return s.replace("P", "").length() == s.replace("Y", "").length(); } } Colored by Color Scripter cs 입력 받은 문자열을 모두 대문자로 치환한다. replace로 각각 P, Y를 제외한 문자열의 길이를 구한다. 그리고 [P를 제외한 문자열의 길이] == [P를 제외한 문자열의 길이] 라면 true 아니면 false를 반환한다. 그리고 다른 분들이 작성한 코드를 보다가 toUpperCase()를 사용하지 않는 방법을 알게 됐다. 1 2 3 4 5 6 7 class Solution ..
2023.01.21 -
K번째수
문제 예제 코드 1) Arrays.copyOfRange 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import java.util.*; class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = {}; int[] temp = new int[commands.length]; for(int i=0; i
2023.01.19 -
자릿수 더하기
문제 1) String으로 형 변환 1-1) 1 2 3 4 5 6 7 8 9 10 11 12 13 public class Solution { public int solution(int n) { String str = ""+n; String[] strarr = str.split(""); int temp = 0; for(String s : strarr){ temp += Integer.parseInt(s); } return temp; } } Colored by Color Scripter cs 1-2) valueOf()를 이용한 형 변환 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import java.util.*; import static java.lang.String.valueOf; pu..
2023.01.19