티스토리 뷰
import java.util.ArrayList;
import java.util.Arrays;
class Solution {
public int[] solution(int[] arr, int divisor) {
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < arr.length; i++) {
if (arr[i] % divisor == 0) {
list.add(arr[i]);
}
}
if (list.size() == 0) {
list.add(-1);
}
int[] answer = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
answer[i] = list.get(i);
}
Arrays.sort(answer);
return answer;
}
}
- 성공
- 리스트에 넣었다가 다시 배열로 바꾸기
'PS > programmers' 카테고리의 다른 글
Level1) 문자열 내 마음대로 정렬하기 (0) | 2020.09.08 |
---|---|
Level1) 두 정수 사이의 합 (0) | 2020.09.08 |
Level1) 같은 숫자는 싫어 (0) | 2020.09.08 |
Level1) 가운데 글자 가져오기 (0) | 2020.09.08 |
Level1) 2016년 (0) | 2020.09.08 |
링크
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- java
- HTTP 완벽 가이드
- 백기선 스터디
- GCP
- REST API
- BOJ
- Spring Security
- dreamcoding
- js promise
- 이펙티브자바 스터디
- 김영한 http
- ㅇㄷㅇㅈ
- JPA 연관관계 매핑
- 이펙티브자바 아이템60
- 킹수빈닷컴
- 프로그래머스
- 프로그래머스 SQL
- JS 딥다이브
- 모던자바스크립트
- 패스트캠퍼스 컴퓨터공학 완주반
- js array
- http
- js api
- 백준
- 김영한 JPA
- 드림코딩
- 이펙티브자바 아이템59
- HTTP 완벽가이드
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- 이펙티브자바
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함