๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ“ ์•Œ๊ณ ๋ฆฌ์ฆ˜

(143)
[์ฝ”๋“œํŠธ๋ฆฌ] ๊ณต๊ฐ„๋ณต์žก๋„ SW์ค‘์‹ฌ๋Œ€ํ•™ ์‚ฌ์—…๋‹จ์—์„œ CodeTree์™€ ํ•จ๊ป˜ ์‹ค์‹œํ•œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ๋Œ€๋น„ ์บ ํ”„์— ์ฐธ์—ฌํ•˜์—ฌ ๊ณต๋ถ€ํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋žจ์˜ ์†Œ์š”์‹œ๊ฐ„ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ, ์ปดํ“จํ„ฐ์˜ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ํ•œ์ •๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ ๊ณต๊ฐ„๋ณต์žก๋„๋„ ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. ๊ณต๊ฐ„๋ณต์žก๋„๋„ ์‹œ๊ฐ„๋ณต์žก๋„์™€ ๋™์ผํ•˜๊ฒŒ ์ ๊ทผ์  ํ‘œ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. function example(n) set arr = [n][n] for i = 0 ... i < n for j = 0 ... j < n arr[i][j] = 1 ๊ณต๊ฐ„๋ณต์žก๋„ = '์ด ์ฝ”๋“œ๊ฐ€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์–ผ๋งˆ๋‚˜ ์ฐจ์ง€ํ•˜๊ณ  ์žˆ์„๊นŒ?' ์œ„ ์ฝ”๋“œ์—์„œ set arr = [n][n] ์ด์™ธ์˜ ๋‹ค๋ฅธ ์ฝ”๋“œ๋Š” ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ฐจ์ง€ํ•˜๊ณ  ์žˆ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์—, ๊ณต๊ฐ„๋ณต์žก๋„๋Š” O(N^2) ์ž…๋‹ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด ๊ณต๊ฐ„๋ณต์žก๋„๋Š” ์™œ ํ•„์š”ํ• ๊นŒ์š”? ๋ฌธ์ œ์—์„œ ๋ฉ”๋ชจ๋ฆฌ ์ œํ•œ์ด 80MB๋ผ๋Š” ์‹์œผ๋กœ..
[์ฝ”๋“œํŠธ๋ฆฌ] ๋ฐ˜๋ณต๋ฌธ์˜ ์‹œ๊ฐ„๋ณต์žก๋„(2) SW์ค‘์‹ฌ๋Œ€ํ•™ ์‚ฌ์—…๋‹จ์—์„œ CodeTree์™€ ํ•จ๊ป˜ ์‹ค์‹œํ•œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ๋Œ€๋น„ ์บ ํ”„์— ์ฐธ์—ฌํ•˜์—ฌ ๊ณต๋ถ€ํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๋ฐ˜๋ณต๋ฌธ ์‹œ๊ฐ„๋ณต์žก๋„ ๋ฌธ์ œ ์ค‘ ์–ด๋ ค์› ๋˜ ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค. (1) function solution(n, m) set sum = 0 set visited = [n][m] for i = 1 ... i
[์ฝ”๋“œํŠธ๋ฆฌ] ๋ฐ˜๋ณต๋ฌธ์˜ ์‹œ๊ฐ„๋ณต์žก๋„(1) SW์ค‘์‹ฌ๋Œ€ํ•™ ์‚ฌ์—…๋‹จ์—์„œ CodeTree์™€ ํ•จ๊ป˜ ์‹ค์‹œํ•œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ๋Œ€๋น„ ์บ ํ”„์— ์ฐธ์—ฌํ•˜์—ฌ ๊ณต๋ถ€ํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. function example(n) while 0 > n or n > 100 if n < 0 n++ else n-- return n ์œ„ ์ฝ”๋“œ์˜ ๊ฒฝ์šฐ n์— ๊ฐ’์— ๋”ฐ๋ผ ์—ฐ์‚ฐ์˜ ํšŸ์ˆ˜๊ฐ€ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ๋ฐ–์— ์—†์Šต๋‹ˆ๋‹ค. ์‚ฌ์‹ค, ์‹œ๊ฐ„๋ณต์žก๋„๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ์ตœ์•…์„ ๊ธฐ์ค€์œผ๋กœ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ์šฐ๋ฆฌ๊ฐ€ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ์ด์œ ๊ฐ€ ํ”„๋กœ๊ทธ๋žจ์˜ ์„ฑ๋Šฅ์„ ์ฒดํฌํ•˜๊ธฐ ์œ„ํ•จ์ด์—ˆ์ฃ ? ๋‹น์—ฐํžˆ ์ž…๋ ฅ๊ฐ’์ด ์•„์ฃผ ํฌ๊ฑฐ๋‚˜ ์‹œ๊ฐ„์ด ์˜ค๋ž˜ ๊ฑธ๋ฆฌ๋Š” ๋ฐ์ดํ„ฐ๋„ ๋“ค์–ด์˜ฌ ๊ฐ€๋Šฅ์„ฑ์ด ์กด์žฌํ•˜๋ฏ€๋กœ ์ตœ์•…์˜ ๊ฒฝ์šฐ๋ฅผ ๊ณ ๋ คํ•˜๋ฉด ์–ด๋– ํ•œ ์ƒํ™ฉ์—์„œ๋„ ํ”„๋กœ๊ทธ๋žจ์˜ ์„ฑ๋Šฅ์ด ๋›ฐ์–ด๋‚œ์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด ์ ์„ ์ƒ๊ธฐํ•œ ์ฑ„๋กœ, ๋ฐ˜๋ณต๋ฌธ์˜ ์‹œ๊ฐ„๋ณต์žก๋„์— ๋Œ€ํ•ด ์•Œ์•„๋ด…์‹œ๋‹ค. for set ..
[์ฝ”๋“œํŠธ๋ฆฌ] ์‹œ๊ฐ„๋ณต์žก๋„์˜ ์ •์˜ SW์ค‘์‹ฌ๋Œ€ํ•™ ์‚ฌ์—…๋‹จ์—์„œ CodeTree์™€ ํ•จ๊ป˜ ์‹ค์‹œํ•œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ๋Œ€๋น„ ์บ ํ”„์— ์ฐธ์—ฌํ•˜์—ฌ ๊ณต๋ถ€ํ•œ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•˜์˜€์Šต๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋žจ์˜ ํšจ์œจ์„ฑ์„ ํ™•์ธํ•˜๋ ค๋ฉด? ๋จผ์ € ์—ฐ์‚ฐ์ด ๋ช‡ ๋ฒˆ ์ง„ํ–‰๋˜์—ˆ๋Š”์ง€ ๊ณ„์‚ฐํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์—ฐ์‚ฐ ํšŸ์ˆ˜๋ฅผ ์„ธ๋Š” ๊ฒƒ์€ ๋งŽ์€ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ๊ณ , ์ฝ”๋“œ๊ฐ€ ๋ณต์žกํ•ด์ง„๋‹ค๋ฉด ๋งค์šฐ ์–ด๋ ค์›Œ์ง‘๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์—ฐ์‚ฐ์˜ ํšŸ์ˆ˜๋ฅผ ์ ๊ทผ์  ํ‘œ๊ธฐ๋ฒ•์„ ํ†ตํ•ด ์ถ”์ƒ์ ์œผ๋กœ ํ‘œํ˜„ํ•œ ๊ฒƒ์ด ๋ฐ”๋กœ ์‹œ๊ฐ„๋ณต์žก๋„ ์ž…๋‹ˆ๋‹ค. set a = 5 if a != 10 print('hello') print ๊ฐ™์€ ๋ฉ”์„œ๋“œ๋ฅผ O(1)์ด๋ผ๊ณ  ๊ฐ€์ •ํ•œ๋‹ค๋ฉด, ๋Œ€์ž…๋„ O(1)์ด๊ณ  print๋„ O(1)์ด๋‹ˆ if a != 10 ๋งŒ ์ •ํ™•ํ•˜๊ฒŒ ์•Œ๋ฉด ๋  ๊ฒƒ ์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๊ฒฐ๊ตญ ๋‹จ์ˆœํžˆ ๋‘ ๊ฐ’์„ ๋น„๊ตํ•˜๋Š” ์—ฐ์‚ฐ์„ ์ˆ˜ํ–‰ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ๊ฒฐ๊ณผ์ ์œผ๋กœ ์กฐ๊ฑด๋ฌธ๋„ O(1)์˜ ์‹œ๊ฐ„๋ณต์žก๋„๋ฅผ ๋ณด..
[PGS] Lv.0 (์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ) 9์ผ์ฐจ ๋ฌธ์ œ ๊ฐœ๋ฏธ ๊ตฐ๋‹จ int solution(int hp) { int jang = hp / 5; hp -= 5 * jang; int byung = hp / 3; hp -= 3 * byung; int answer = hp + jang + byung; return answer; } ๋ชจ์Šค๋ถ€ํ˜ธ (1) char MORSE_CODE[26][5] = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."}; string solution(string letter) { string word = ""; ..
[PGS] Lv.0 (์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ) 8์ผ์ฐจ ๋ฌธ์ œ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค C++ ๋ฐฐ์—ด ์ž๋ฅด๊ธฐ vector solution(vector numbers, int num1, int num2) { vector answer; for(num1; num199) { answer.push_back(alpha[age / 100]); age -= 100*(age/100); } if(tmp>9) answer.push_back(alpha[age / 10]); answer.push_back(alpha[age % 10]); return answer; } → ์ƒˆ๋กœ์šด ํ’€์ด string answer = to_string(age); for(auto& v : answer) v += 'a'-'0'; return answer; // for(๋ฐ˜๋ณต๋  ์ง€์—ญ๋ณ€์ˆ˜ : ๋ฐฐ์—ด) -> ์ง€์—ญ๋ณ€์ˆ˜๊ฐ€ ๋ฐฐ์—ด ๊ธธ์ด๋งŒํผ ๋ฐ˜๋ณต๋จ..
[PGS] Lv.0 (์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์ž…๋ฌธ) 7์ผ์ฐจ ๋ฌธ์ œ ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค C++ ํŠน์ • ๋ฌธ์ž ์ œ๊ฑฐํ•˜๊ธฐ string solution(string my_string, string letter) { string answer = ""; answer = regex_replace(my_string, regex(letter), ""); return answer; } ๊ฐ๋„๊ธฐ int solution(int angle) { if(angle==90) return 2; if(angle == 180) return 4; if(angle>0 && angle
[PGS] Lv.1 : ์†Œ์ˆ˜ ๋งŒ๋“ค๊ธฐ https://school.programmers.co.kr/learn/courses/30/lessons/12977 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ๋ฌธ์ œ ์„ค๋ช… ์ฃผ์–ด์ง„ ์ˆซ์ž ์ค‘ 3๊ฐœ์˜ ์ˆ˜๋ฅผ ๋”ํ–ˆ์„ ๋•Œ ์†Œ์ˆ˜๊ฐ€ ๋˜๋Š” ๊ฒฝ์šฐ์˜ ๊ฐœ์ˆ˜๋ฅผ ๊ตฌํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ˆซ์ž๋“ค์ด ๋“ค์–ด์žˆ๋Š” ๋ฐฐ์—ด nums๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์งˆ ๋•Œ, nums์— ์žˆ๋Š” ์ˆซ์ž๋“ค ์ค‘ ์„œ๋กœ ๋‹ค๋ฅธ 3๊ฐœ๋ฅผ ๊ณจ๋ผ ๋”ํ–ˆ์„ ๋•Œ ์†Œ์ˆ˜๊ฐ€ ๋˜๋Š” ๊ฒฝ์šฐ์˜ ๊ฐœ์ˆ˜๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ œํ•œ์‚ฌํ•ญ nums์— ๋“ค์–ด์žˆ๋Š” ์ˆซ์ž์˜ ๊ฐœ์ˆ˜๋Š” 3๊ฐœ ์ด์ƒ 50๊ฐœ ์ดํ•˜์ž…๋‹ˆ๋‹ค. nums์˜ ๊ฐ ์›์†Œ๋Š” 1 ์ด์ƒ..

728x90