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

๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ

(159)
[Programmers] ํฌ๋ ˆ์ธ ์ธํ˜•๋ฝ‘๊ธฐ ๊ฒŒ์ž„ ๋‚˜์˜ ์ฝ”๋“œ def solution(board, moves): stack = [] answer = [] imp = [] cnt = 0 # ๋นˆ์นธ์„ ์ œ์™ธํ•˜์—ฌ ๋‚จ์€ ์ธํ˜•๋งŒ ๋‚จ๊ธด ์ƒˆ๋กœ์šด ๋ฐฐ์—ด ๋งŒ๋“ ๋‹ค. for i in range(len(board)): for t in range(len(board)): if board[t][i] != 0: stack.append(board[t][i]) stack.reverse() answer.append(stack) stack = [] # ์ธํ˜•์„ ์ƒˆ๋กœ์šด ๋ฐ”๊ตฌ๋‹ˆ์— ๋„ฃ์œผ๋ฉด์„œ ๋งˆ์ง€๋ง‰ ์›์†Œ์™€ ๊ทธ ์ „ ์›์†Œ๊ฐ€ ๊ฐ™์œผ๋ฉด pop ์‹œํ‚จ๋‹ค. # cnt ๋Š” ์ธํ˜•์ด ์‚ฌ๋ผ์ง€๋Š” ํšŸ์ˆ˜์ด๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ๋ผ์ง„ ์ธํ˜•์˜ ๊ฐœ์ˆ˜๋Š” ์ด ๊ฐ’์˜ 2๋ฐฐ์ด๋‹ค. for l in moves: if len(answer[l-1]) > 0: i..
[1day - 6day TIL] 100 days of swift 1์ผ์ฐจ Coursera ๊ฐ•์˜์™€ ๊ฒน์น˜๋Š” ๋ถ€๋ถ„์ด ๋งŽ์•„์„œ ๊ณต๋ถ€ํ•˜๋Š” ๋ฐ์— ํฌ๊ฒŒ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ์ง€ ์•Š์•˜๋‹ค. ๊ทธ๋ž˜๋„ ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ ๋œ ๊ฐœ๋…๋„ ์žˆ์œผ๋‹ˆ ์ •๋ฆฌ๋ฅผ ํ•ด๋ณด์ž. Multi-line strings var str2 = """ This goes \ over multiple \ lines """ //output: This goes over multiple lines => / ๋ฅผ ํ™œ์šฉํ•ด ๋ฌธ์žฅ์ด ๋‚˜๋‰˜์ง€ ์•Š๊ณ  ํ•œ ๋ฌธ์žฅ์œผ๋กœ ๋ฌธ์ž์—ด์„ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ๋‹ค. ๋ฌธ์ž์—ด์ด ๊ธธ ๋•Œ ๊น”๋”ํ•œ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ์ข‹์„ ๊ฒƒ ๊ฐ™๋‹ค. var str1 = """ This goes over multiple lines """ //output: // This goes // over multiple // lines => ์ด ์•„์ด๋Š” ์ž…๋ ฅํ•œ ๊ทธ๋Œ€๋กœ ๋ฌธ์ž์—ด์ด ์‚ฐ์ถœ๋œ๋‹ค. 2..
[Programmers] ์—†๋Š” ์ˆซ์ž ๋”ํ•˜๊ธฐ ๋ฌธ์ œ 0๋ถ€ํ„ฐ 9๊นŒ์ง€์˜ ์ˆซ์ž ์ค‘ ์ผ๋ถ€๊ฐ€ ๋“ค์–ด์žˆ๋Š” ์ •์ˆ˜ ๋ฐฐ์—ด numbers๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. numbers์—์„œ ์ฐพ์„ ์ˆ˜ ์—†๋Š” 0๋ถ€ํ„ฐ 9๊นŒ์ง€์˜ ์ˆซ์ž๋ฅผ ๋ชจ๋‘ ์ฐพ์•„ ๋”ํ•œ ์ˆ˜๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ œํ•œ์‚ฌํ•ญ 1 ≤ numbers์˜ ๊ธธ์ด ≤ 9 0 ≤ numbers์˜ ๋ชจ๋“  ์›์†Œ ≤ 9 numbers์˜ ๋ชจ๋“  ์›์†Œ๋Š” ์„œ๋กœ ๋‹ค๋ฆ…๋‹ˆ๋‹ค. ๋‚˜์˜ ์ฝ”๋“œ def solution(numbers): cnt = [] for i in range(1,10): cnt.append(i) return sum(cnt) - sum(numbers)
[Programmers] ์ˆซ์ž ๋ฌธ์ž์—ด๊ณผ ์˜๋‹จ์–ด ๋ฌธ์ œ ๋„ค์˜ค์™€ ํ”„๋กœ๋„๊ฐ€ ์ˆซ์ž๋†€์ด๋ฅผ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋„ค์˜ค๊ฐ€ ํ”„๋กœ๋„์—๊ฒŒ ์ˆซ์ž๋ฅผ ๊ฑด๋„ฌ ๋•Œ ์ผ๋ถ€ ์ž๋ฆฟ์ˆ˜๋ฅผ ์˜๋‹จ์–ด๋กœ ๋ฐ”๊พผ ์นด๋“œ๋ฅผ ๊ฑด๋„ค์ฃผ๋ฉด ํ”„๋กœ๋„๋Š” ์›๋ž˜ ์ˆซ์ž๋ฅผ ์ฐพ๋Š” ๊ฒŒ์ž„์ž…๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ์ˆซ์ž์˜ ์ผ๋ถ€ ์ž๋ฆฟ์ˆ˜๋ฅผ ์˜๋‹จ์–ด๋กœ ๋ฐ”๊พธ๋Š” ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค. 1478 → "one4seveneight" 234567 → "23four5six7" 10203 → "1zerotwozero3" ์ด๋ ‡๊ฒŒ ์ˆซ์ž์˜ ์ผ๋ถ€ ์ž๋ฆฟ์ˆ˜๊ฐ€ ์˜๋‹จ์–ด๋กœ ๋ฐ”๋€Œ์–ด์กŒ๊ฑฐ๋‚˜, ํ˜น์€ ๋ฐ”๋€Œ์ง€ ์•Š๊ณ  ๊ทธ๋Œ€๋กœ์ธ ๋ฌธ์ž์—ด s๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. s๊ฐ€ ์˜๋ฏธํ•˜๋Š” ์›๋ž˜ ์ˆซ์ž๋ฅผ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ฐธ๊ณ ๋กœ ๊ฐ ์ˆซ์ž์— ๋Œ€์‘๋˜๋Š” ์˜๋‹จ์–ด๋Š” ๋‹ค์Œ ํ‘œ์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. 0 zero 1 one 2 two 3 three 4 four 5 five 6 six 7 seven 8 ei..
[Programmers] ์Œ์–‘ ๋”ํ•˜๊ธฐ ๋ฌธ์ œ ์–ด๋–ค ์ •์ˆ˜๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด ์ •์ˆ˜๋“ค์˜ ์ ˆ๋Œ“๊ฐ’์„ ์ฐจ๋ก€๋Œ€๋กœ ๋‹ด์€ ์ •์ˆ˜ ๋ฐฐ์—ด absolutes์™€ ์ด ์ •์ˆ˜๋“ค์˜ ๋ถ€ํ˜ธ๋ฅผ ์ฐจ๋ก€๋Œ€๋กœ ๋‹ด์€ ๋ถˆ๋ฆฌ์–ธ ๋ฐฐ์—ด signs๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. ์‹ค์ œ ์ •์ˆ˜๋“ค์˜ ํ•ฉ์„ ๊ตฌํ•˜์—ฌ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ œํ•œ ์‚ฌํ•ญ absolutes์˜ ๊ธธ์ด๋Š” 1 ์ด์ƒ 1,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค. absolutes์˜ ๋ชจ๋“  ์ˆ˜๋Š” ๊ฐ๊ฐ 1 ์ด์ƒ 1,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค. signs์˜ ๊ธธ์ด๋Š” absolutes์˜ ๊ธธ์ด์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค. signs[i] ๊ฐ€ ์ฐธ์ด๋ฉด absolutes[i] ์˜ ์‹ค์ œ ์ •์ˆ˜๊ฐ€ ์–‘์ˆ˜์ž„์„, ๊ทธ๋ ‡์ง€ ์•Š์œผ๋ฉด ์Œ์ˆ˜์ž„์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ๋‚˜์˜ ์ฝ”๋“œ def solution(absolutes, signs): t = 0 for i in range(len(signs)): if sign..
[Programmers] ๋‚ด์  ๋ฌธ์ œ ๊ธธ์ด๊ฐ€ ๊ฐ™์€ ๋‘ 1์ฐจ์› ์ •์ˆ˜ ๋ฐฐ์—ด a, b๊ฐ€ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ฃผ์–ด์ง‘๋‹ˆ๋‹ค. a์™€ b์˜ ๋‚ด์ ์„ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ด๋•Œ, a์™€ b์˜ ๋‚ด์ ์€ a[0]*b[0] + a[1]*b[1] + ... + a[n-1]*b[n-1] ์ž…๋‹ˆ๋‹ค. (n์€ a, b์˜ ๊ธธ์ด) ์ œํ•œ ์‚ฌํ•ญ a, b์˜ ๊ธธ์ด๋Š” 1 ์ด์ƒ 1,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค. a, b์˜ ๋ชจ๋“  ์ˆ˜๋Š” -1,000 ์ด์ƒ 1,000 ์ดํ•˜์ž…๋‹ˆ๋‹ค. [1,2,3,4] [-3,-1,0,2] 3 [-1,0,1] [1,0,-1] -2 ๋‚˜์˜ ์ฝ”๋“œ def solution(a, b): t = 0 for i in range(len(a)): t += (a[i] * b[i]) return t
[Programmers] ๋กœ๋˜์˜ ์ตœ๊ณ  ์ˆœ์œ„์™€ ์ตœ์ € ์ˆœ์œ„ ๋ฌธ์ œ ๋กœ๋˜ 6/45(์ดํ•˜ '๋กœ๋˜'๋กœ ํ‘œ๊ธฐ)๋Š” 1๋ถ€ํ„ฐ 45๊นŒ์ง€์˜ ์ˆซ์ž ์ค‘ 6๊ฐœ๋ฅผ ์ฐ์–ด์„œ ๋งžํžˆ๋Š” ๋Œ€ํ‘œ์ ์ธ ๋ณต๊ถŒ์ž…๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” ๋กœ๋˜์˜ ์ˆœ์œ„๋ฅผ ์ •ํ•˜๋Š” ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค. 1 6๊ฐœ ๋ฒˆํ˜ธ๊ฐ€ ๋ชจ๋‘ ์ผ์น˜ 2 5๊ฐœ ๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ 3 4๊ฐœ ๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ 4 3๊ฐœ ๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ 5 2๊ฐœ ๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ 6(๋‚™์ฒจ) ๊ทธ ์™ธ ๋กœ๋˜๋ฅผ ๊ตฌ๋งคํ•œ ๋ฏผ์šฐ๋Š” ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐœํ‘œ์ผ์„ ํ•™์ˆ˜๊ณ ๋Œ€ํ•˜๊ณ  ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ, ๋ฏผ์šฐ์˜ ๋™์ƒ์ด ๋กœ๋˜์— ๋‚™์„œ๋ฅผ ํ•˜์—ฌ, ์ผ๋ถ€ ๋ฒˆํ˜ธ๋ฅผ ์•Œ์•„๋ณผ ์ˆ˜ ์—†๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐœํ‘œ ํ›„, ๋ฏผ์šฐ๋Š” ์ž์‹ ์ด ๊ตฌ๋งคํ–ˆ๋˜ ๋กœ๋˜๋กœ ๋‹น์ฒจ์ด ๊ฐ€๋Šฅํ–ˆ๋˜ ์ตœ๊ณ  ์ˆœ์œ„์™€ ์ตœ์ € ์ˆœ์œ„๋ฅผ ์•Œ์•„๋ณด๊ณ  ์‹ถ์–ด ์กŒ์Šต๋‹ˆ๋‹ค. ์•Œ์•„๋ณผ ์ˆ˜ ์—†๋Š” ๋ฒˆํ˜ธ๋ฅผ 0์œผ๋กœ ํ‘œ๊ธฐํ•˜๊ธฐ๋กœ ํ•˜๊ณ , ๋ฏผ์šฐ๊ฐ€ ๊ตฌ๋งคํ•œ ๋กœ๋˜ ๋ฒˆํ˜ธ 6๊ฐœ๊ฐ€ 44, 1, 0, 0, 31 25๋ผ๊ณ  ๊ฐ€์ •ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋‹น์ฒจ ๋ฒˆํ˜ธ 6๊ฐœ๊ฐ€ 3..
[Programmers] ์‹ ๊ณ  ๊ฒฐ๊ณผ ๋ฐ›๊ธฐ ๋ฌธ์ œ ๋ฌธ์ œ ์„ค๋ช… ์‹ ์ž…์‚ฌ์› ๋ฌด์ง€๋Š” ๊ฒŒ์‹œํŒ ๋ถˆ๋Ÿ‰ ์ด์šฉ์ž๋ฅผ ์‹ ๊ณ ํ•˜๊ณ  ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ๋ฉ”์ผ๋กœ ๋ฐœ์†กํ•˜๋Š” ์‹œ์Šคํ…œ์„ ๊ฐœ๋ฐœํ•˜๋ ค ํ•ฉ๋‹ˆ๋‹ค. ๋ฌด์ง€๊ฐ€ ๊ฐœ๋ฐœํ•˜๋ ค๋Š” ์‹œ์Šคํ…œ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ ์œ ์ €๋Š” ํ•œ ๋ฒˆ์— ํ•œ ๋ช…์˜ ์œ ์ €๋ฅผ ์‹ ๊ณ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์‹ ๊ณ  ํšŸ์ˆ˜์— ์ œํ•œ์€ ์—†์Šต๋‹ˆ๋‹ค. ์„œ๋กœ ๋‹ค๋ฅธ ์œ ์ €๋ฅผ ๊ณ„์†ํ•ด์„œ ์‹ ๊ณ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•œ ์œ ์ €๋ฅผ ์—ฌ๋Ÿฌ ๋ฒˆ ์‹ ๊ณ ํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ, ๋™์ผํ•œ ์œ ์ €์— ๋Œ€ํ•œ ์‹ ๊ณ  ํšŸ์ˆ˜๋Š” 1ํšŒ๋กœ ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค. k๋ฒˆ ์ด์ƒ ์‹ ๊ณ ๋œ ์œ ์ €๋Š” ๊ฒŒ์‹œํŒ ์ด์šฉ์ด ์ •์ง€๋˜๋ฉฐ, ํ•ด๋‹น ์œ ์ €๋ฅผ ์‹ ๊ณ ํ•œ ๋ชจ๋“  ์œ ์ €์—๊ฒŒ ์ •์ง€ ์‚ฌ์‹ค์„ ๋ฉ”์ผ๋กœ ๋ฐœ์†กํ•ฉ๋‹ˆ๋‹ค. ์œ ์ €๊ฐ€ ์‹ ๊ณ ํ•œ ๋ชจ๋“  ๋‚ด์šฉ์„ ์ทจํ•ฉํ•˜์—ฌ ๋งˆ์ง€๋ง‰์— ํ•œ๊บผ๋ฒˆ์— ๊ฒŒ์‹œํŒ ์ด์šฉ ์ •์ง€๋ฅผ ์‹œํ‚ค๋ฉด์„œ ์ •์ง€ ๋ฉ”์ผ์„ ๋ฐœ์†กํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ์ „์ฒด ์œ ์ € ๋ชฉ๋ก์ด ["muzi", "frodo", "apeach", "neo"]์ด๊ณ , k ..