
Solution 1) 내 풀이
import java.util.stream.IntStream;
class Solution {
public int[] solution(int n) {
IntStream stream = IntStream.iterate(n, i -> i != 1, i -> i % 2 == 0 ? i / 2 : 3 * i + 1);
stream = IntStream.concat(stream, IntStream.of(1));
return stream.toArray();
}
}
'연습문제 > 프로그래머스, 기초 트레이닝' 카테고리의 다른 글
| 간단한 논리 연산(논리 연산자) (0) | 2023.10.24 |
|---|---|
| 배열 만들기 4 (1) | 2023.10.23 |
| 카운트 업(Stream 활용하기) (1) | 2023.10.23 |
| 배열 만들기2 (1) | 2023.10.23 |
| 수열과 구간 쿼리 4 (반복문의 초기치 설정..) (0) | 2023.10.23 |