๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

Algorithm/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค9

[Java] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - 3์ง„๋ฒ• ๋’ค์ง‘๊ธฐ (์ •๋‹ต / ์„ค๋ช…) ๐Ÿ’ก๋ฌธ์ œ ์„ค๋ช… ์ž์—ฐ์ˆ˜ n์ด ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. n์„ 3์ง„๋ฒ• ์ƒ์—์„œ ์•ž๋’ค๋กœ ๋’ค์ง‘์€ ํ›„, ์ด๋ฅผ ๋‹ค์‹œ 10์ง„๋ฒ•์œผ๋กœ ํ‘œํ˜„ํ•œ ์ˆ˜๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ž…์ถœ๋ ฅ ์˜ˆ 45 7 125 229 ์ž…์ถœ๋ ฅ ์˜ˆ #1 n (10์ง„๋ฒ•)n (3์ง„๋ฒ•)์•ž๋’ค ๋ฐ˜์ „(3์ง„๋ฒ•)10์ง„๋ฒ•์œผ๋กœ ํ‘œํ˜„ 45 1200 0021 7 ๋”ฐ๋ผ์„œ 7์„ return ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ #2 n (10์ง„๋ฒ•)n (3์ง„๋ฒ•)์•ž๋’ค ๋ฐ˜์ „(3์ง„๋ฒ•)10์ง„๋ฒ•์œผ๋กœ ํ‘œํ˜„ 125 11122 22111 229 ๋”ฐ๋ผ์„œ 229๋ฅผ return ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป์ œ์ถœํ•œ ์ •๋‹ต์ฝ”๋“œ class Solution { public int solution(int n) { String answer = ""; while(n > 0){ answer += n%3; n.. 2022. 3. 11.
[JAVA] 1 ๋ถ€ํ„ฐ 100๊นŒ์ง€ ์ˆซ์ž๋ฅผ ํ•ฉํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜ Class Solution { public int solution(int num){ int sum = num*(num+1)/2; return sum; } } public class ์ˆซ์ž๋”ํ•˜๊ธฐ { public static void main(String[] args) { Solution test = new Solution(); System.out.println(test.solution(100)); } } // ๊ฒฐ๊ณผ : 5050 for ๋ฌธ์„ ์ด์šฉํ•˜๋Š”๊ฒƒ๋ณด๋‹ค ํ›จ์”ฌ ํšจ์œจ์ ์ด๋‹ค :) 2022. 2. 26.
[JAVA] ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - ์†Œ์ˆ˜ ์—๋ผํ† ์Šคํ…Œ๋„ค์Šค์˜ ์ฒด class Solution { public int solution(int n) { int answer = 0; int[] number = new int[n+1]; //2๋ถ€ํ„ฐ n๊นŒ์ง€์˜ ์ˆ˜๋ฅผ ๋ฐฐ์—ด์— ๋„ฃ๋Š”๋‹ค. for(int i=2; i 2022. 2. 23.
300x250

์ฝ”๋“œ