티스토리 뷰

class Solution {
    public long[] solution(int x, int n) {
        long[] answer = new long[n];

        long temp = x;
        int index = 0;
        while (index != n) {
            answer[index] = temp;
            index++;
            temp += x;
        }

        return answer;
    }
}

- 성공

 

- for문보다 while 문 생각이 먼저나서 while문으로 풀었음

 

 

class Solution {
  public long[] solution(long x, int n) {
      long[] answer = new long[n];
      for(int i = 0; i < n; i++){
          answer[i] = x * (i + 1);
      }
      return answer;
  }
}

- 다른 사람 풀이

- 제일 깔끔해보임 

 

'PS > programmers' 카테고리의 다른 글

Level2) 프린터  (0) 2020.10.09
Level1) 두 개 뽑아서 더하기  (0) 2020.10.08
Level1) 하샤드 수  (0) 2020.09.12
Level1) 콜라츠 추측  (0) 2020.09.12
Level1) 최대공약수와 최소공배수  (0) 2020.09.12