144. 배열 만들기 5

김해준's avatar
Dec 28, 2025
144. 배열 만들기 5

사용언어 : Java

문제
notion image
풀이
class Solution { public int[] solution(String[] intStrs, int k, int s, int l) { int[] temp = new int[intStrs.length]; // 1. 해당 양식에 맞춰 intStrs를 자르기 for(int i = 0 ; i < intStrs.length; i++) { String tempStr = ""; for(int j = s ; j < s + l; j++) { tempStr += intStrs[i].charAt(j); } temp[i] = Integer.parseInt(tempStr); } // 2. 잘라낸 temp의 원소 중 k 보다 큰값을 가지는 원소의 수 구하기(배열의 크기) int count = 0; for(int i = 0 ; i < temp.length; i++) { if(temp[i] > k)count++; } // 3. 조건에 맞는 원소의 수만큼 반환값 배열의 크기를 지정하여 선언 int[] answer = new int[count]; // 4. 조건에 맞는 원소 옮기기 int index = 0; for(int i = 0 ; i < temp.length; i++) { if(temp[i] > k) { answer[index] = temp[i]; index++; } } return answer; } }
notion image
Share article