[TIL/ES] int ๊ฐ’ ๋ฒ”์œ„ ๋ฒ—์–ด๋‚˜๋Š” ๊ฒฝ์šฐ

import java.util.*;

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

answer[i] = (i+1) * x ๋กœ ๊ฐ’์„ ๋‹ด๋Š” ๊ฒฝ์šฐ int๊ฐ’์—์„œ long์œผ๋กœ ๋„˜์–ด๊ฐ€๊ธฐ ๋•Œ๋ฌธ์— int ๊ฐ’ ์˜ค๋ฒ„ํ”Œ๋กœ์šฐ๊ฐ€ ์ผ์–ด๋‚œ๋‹ค.

๋”ฐ๋ผ์„œ ๊ณ„์‚ฐ ๊ณผ์ •์—์„œ ์บ์ŠคํŒ…์„ ํ•ด์ค˜์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— x๊ฐ’ ์•ž์— (long)์œผ๋กœ ์ง์ ‘ ํ˜•๋ณ€ํ™˜์„ ํ•ด์ค˜์•ผํ•จ!

(int->long)

  • ๋„ค์ด๋ฒ„ ๋ธ”๋Ÿฌ๊ทธ ๊ณต์œ ํ•˜๊ธฐ
  • ๋„ค์ด๋ฒ„ ๋ฐด๋“œ์— ๊ณต์œ ํ•˜๊ธฐ
  • ํŽ˜์ด์Šค๋ถ ๊ณต์œ ํ•˜๊ธฐ
  • ์นด์นด์˜ค์Šคํ† ๋ฆฌ ๊ณต์œ ํ•˜๊ธฐ