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();
    }
}

 

+ Recent posts