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

๊ณ ์ฐจํ•จ์ˆ˜ํ•จ์ˆ˜๋ฅผ ๋งˆ์น˜ ํด๋ž˜์Šค์—์„œ ๋งŒ๋“ค์–ด๋‚ธ ์ธ์Šคํ„ด์Šค์ฒ˜๋Ÿผ ์ทจ๊ธ‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.ํ•จ์ˆ˜๋ฅผ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„˜๊ฒจ์ค„ ์ˆ˜๋„ ์žˆ๊ณ , ๊ฒฐ๊ณผ๊ฐ’์œผ๋กœ ๋ฐ˜ํ™˜๋ฐ›์„ ์ˆ˜๋„ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.์ฝ”ํ‹€๋ฆฐ์—์„œ๋Š” ๋ชจ๋“  ํ•จ์ˆ˜๋ฅผ ๊ณ ์ฐจํ•จ์ˆ˜๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค. ๊ณ ์ฐจํ•จ์ˆ˜ ๊ตฌํ˜„๋ฒ•fun main(){    b(::a)}fun a (str:String){    println("$str ํ•จ์ˆ˜ : a")}fun b (function: (String)->Unit) {    function("b๊ฐ€ ํ˜ธ์ถœํ•œ")}์ถœ๋ ฅb๊ฐ€ ํ˜ธ์ถœํ•œ ํ•จ์ˆ˜ : aํ•จ์ˆ˜ a๋ฅผ ๊ณ ์ฐจํ•จ์ˆ˜ ํ˜•์‹์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ ๋‹ค.ํ•จ์ˆ˜๋ฅผ ์ž๋ฃŒํ˜•์œผ๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฐฉ๋ฒ•์€ ๊ด„ํ˜ธ ์•ˆ์— ํ•จ์ˆ˜๊ฐ€ ๋ฐ›์„ ํŒŒ๋ผ๋ฏธํ„ฐ์˜ ์ž๋ฃŒํ˜•์„ ๋‚˜์—ดํ•˜๊ณ  '->'๋กœ ํ™”์‚ดํ‘œ๋ฅผ ๋งŒ๋“  ๋’ค ํ•จ์ˆ˜์˜ ๋ฐ˜ํ™˜ํ˜•์„ ์“ฐ๋ฉด ๋œ๋‹ค.ํ•จ์ˆ˜ a๋Š” ๋ฐ˜ํ™˜ํ˜•์ด ์—†์œผ๋‹ˆ ๊ฐ’์ด ์—†๋‹ค๋Š” ์˜๋ฏธ์˜ U..
์Šค์ฝ”ํ”„ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ ๋‚ด์—์„œ ๋ณ€์ˆ˜, ํ•จ์ˆ˜, ํด๋ž˜์Šค๋“ค์„ ์„œ๋กœ ๊ณต์œ ํ•˜๋ฉฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ณต์šฉ๋ฒ”์œ„๋ฅผ ์ œ์–ดํ•˜๋Š” ๋‹จ์œ„๋‹ค. ์Šค์ฝ”ํ”„๊ฐ€ ์ง€์ •๋˜๋Š” ๋ฒ”์œ„ํŒจํ‚ค์ง€ ๋‚ด๋ถ€ํŒจํ‚ค์ง€ ๋‚ด๋ถ€์— ๋ณ€์ˆ˜, ํ•จ์ˆ˜, ํด๋ž˜์Šค๊ฐ€ ์žˆ๋‹ค๋ฉด ํŒจํ‚ค์ง€ ๋‚ด๋ถ€์— ์žˆ๋Š” ์ด๋“ค์€ ๋ชจ๋‘ ํŒจํ‚ค์ง€ ๋ผ๋Š” ํ•˜๋‚˜์˜ ์Šค์ฝ”ํ”„ ์•ˆ์— ์žˆ๋Š” ๋ฉค๋ฒ„๋“ค์ด๋‹ค.ํด๋ž˜์Šค ๋‚ด๋ถ€ํด๋ž˜์Šค๋„ ์Šค์ฝ”ํ”„ ๊ธฐ๋Šฅ์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‹ค.ํด๋ž˜์Šค ๋‚ด๋ถ€์— ๋ณ€์ˆ˜, ํ•จ์ˆ˜๊ฐ€ ์žˆ๋‹ค๋ฉด ํด๋ž˜์Šค ๋‚ด๋ถ€์— ์žˆ๋Š” ์ด๋“ค์€ ๋ชจ๋‘ ํด๋ž˜์Šค ๋ผ๋Š” ํ•˜๋‚˜์˜ ์Šค์ฝ”ํ”„ ์•ˆ์— ์žˆ๋Š” ๋ฉค๋ฒ„๋“ค์ด๋‹ค.ํŒจํ‚ค์ง€ ๋‚ด๋ถ€์— ์žˆ๋Š” ์Šค์ฝ”ํ”„ ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ํด๋ž˜์Šค๋Š” ํ•˜์œ„ ์Šค์ฝ”ํ”„๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.ํ•จ์ˆ˜ ๋‚ด๋ถ€ํด๋ž˜์Šค์™€ ์Šค์ฝ”ํ”„์— ๋Œ€ํ•œ ๊ฐœ๋…์ด ๋™์ผํ•˜๋‹ค. ์Šค์ฝ”ํ”„์— ๋Œ€ํ•œ ์„ธ๊ฐ€์ง€ ๊ทœ์น™์Šค์ฝ”ํ”„ ์™ธ๋ถ€์—์„œ๋Š” ์Šค์ฝ”ํ”„ ๋‚ด๋ถ€์˜ ๋ฉค๋ฒ„๋ฅผ '์ฐธ์กฐ ์—ฐ์‚ฐ์ž'๋กœ๋งŒ ์ฐธ์กฐ๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.๋™์ผ ์Šค์ฝ”ํ”„ ๋‚ด์—์„œ๋Š” ๋ฉค๋ฒ„๋“ค์„ ๊ณต์œ ํ•  ์ˆ˜ ์žˆ๋‹ค.val a ..
๋ฌผ๋ฆฌ์  ๊ตฌ์กฐ"ํ”„๋กœ์ ํŠธ > ๋ชจ๋“ˆ > ํด๋” & ํŒŒ์ผ" ๊ตฌ์กฐ๊ฐ€ ์‹ค์ œ ํŒŒ์ผ ์‹œ์Šคํ…œ์— ๊ธฐ๋ฐ˜ํ•œ ๋ฌผ๋ฆฌ์  ๊ตฌ์กฐ๋ฅผ ๋‹ด๋‹นํ•œ๋‹ค. ํ”„๋กœ์ ํŠธ์ฝ”ํ‹€๋ฆฐ์œผ๋กœ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์งค ๋•Œ ๊ด€๋ จ๋œ ๋ชจ๋“  ๋‚ด์šฉ์„ ๋‹ด๋Š” ํฐ ํ‹€์ด๋‹ค. ๋ชจ๋“ˆํ•˜๋‚˜์˜ ํ”„๋กœ์ ํŠธ๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ชจ๋“ˆ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค.๋ชจ๋“ˆ์„ ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง์ ‘ ๊ตฌํ˜„ํ•  ์ˆ˜๋„, ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ชจ๋“ˆ์„ ์ด์šฉํ•ด ๋ถ™์ผ ์ˆ˜๋„ ์žˆ๋‹ค. ํด๋” & ํŒŒ์ผ๋ชจ๋“ˆ์•ˆ์—๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ ํด๋”์™€ ํŒŒ์ผ์ด ๋“ค์–ด๊ฐ€ ์žˆ๋‹ค.์ฝ”ํ‹€๋ฆฐ ์ฝ”๋“œํŒŒ์ผ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋ชจ๋“ˆ๊ด€ ๊ด€๋ จ๋œ ์„ค์ • ๋ฐ ๋ฆฌ์†Œ์Šค ํŒŒ์ผ์ด ํฌํ•จ ๋  ์ˆ˜ ์žˆ๋‹ค. ๋…ผ๋ฆฌ์  ๊ตฌ์กฐํŒจํ‚ค์ง€ ํŒจํ‚ค์ง€๊ฐœ๋ฐœ ์‹œ ์†Œ์Šค์ฝ”๋“œ์˜ ์†Œ์†์„ ์ง€์ •ํ•˜๊ธฐ ์œ„ํ•œ ๋…ผ๋ฆฌ์  ๋‹จ์œ„๋‹ค.์ฝ”๋“œ๋ฅผ ์ž‘์„ฑ ํ•  ๋•Œ ์ฝ”๋“œ ์•ˆ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์ด๋ฆ„์ด ์šฉ๋„์— ๋”ฐ๋ผ ์„œ๋กœ ์ถฉ๋Œํ•˜์ง€ ์•Š๋„๋ก ์œ ๋‹ˆํฌํ•œ ํŒจํ‚ค์ง€ ์ด๋ฆ„์„ ๋ถ™์ด๋Š”๊ฒƒ์ด ์ข‹๋‹ค.์ผ๋ฐ˜์ ์œผ๋กœ ํŒจํ‚ค์ง€ ์ด๋ฆ„์„ ์ง€์„ ๋•Œ๋Š” ๊ฐœ๋ฐœํ•œ ํšŒ์‚ฌ๊ฐ€ ..
๋ฌธ์ œ๋ฆฟ์ฝ”๋“œ 1845. Seat Reservation Managerhttps://leetcode.com/problems/seat-reservation-manager/  ์ฝ”๋“œimport heapqclass SeatManager: def __init__(self, n): self.can_reserve = list(range(1, n + 1)) heapq.heapify(self.can_reserve) def reserve(self): return heapq.heappop(self.can_reserve) def unreserve(self, seatNumber): heapq.heappush(self.can_reserve, seatNumber)..
๋ฌธ์ œ๋ฆฟ์ฝ”๋“œ 921. Minimum Add to Make Parentheses Valishttps://leetcode.com/problems/minimum-add-to-make-parentheses-valid/ ์ฝ”๋“œclass Solution(object): def minAddToMakeValid(self, s): s = deque(s) stack = [] item = s.popleft() stack.append(item) while s: item = s.popleft() if not stack: stack.append(item) else: ..
๋ฌธ์ œ2390. Removing Stars From a String https://leetcode.com/problems/removing-stars-from-a-string/ ์ฝ”๋“œclass Solution(object): def removeStars(self, s): s = list(s) while '*' in s: for i in range(len(s)-1): if s[i + 1] == '*': s.pop(i+1) s.pop(i) break return ''.join(s) ํ’€์ดs = list(s)๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋ฐ›์€ ๋ฌธ์ž..
๋ฌธ์ œ๋ฆฟ์ฝ”๋“œ 1823. Find the Winner of the Circular Gamehttps://leetcode.com/problems/find-the-winner-of-the-circular-game/solutions/ ์ฝ”๋“œclass Solution: def findTheWinner(self, n: int, k: int) -> int: circle = [i for i in range(1, n+1)] count = 1 turn = 0 while len(circle) != 1: if count == k: circle.pop(turn) count = 1 ..
๋ฌธ์ œ๋ฐฑ์ค€ ๊ฑธ๊ทธ๋ฃน ๋งˆ์Šคํ„ฐ ์ค€์„์ด https://www.acmicpc.net/problem/16165 ์ฝ”๋“œn, m = map(int, input().split()) # ๊ฑธ๊ทธ๋ฃน์˜ ์ˆ˜, ๋งžํ˜€์•ผ ํ•  ๋ฌธ์ œ์˜ ์ˆ˜idol_dic = {}for _ in range(n): team_name = input() team_member_num = int(input()) team_member = [] for _ in range(team_member_num): team_member.append(input()) idol_dic[team_name] = team_memberfor _ in range(m): quiz = input() quiz_type = int(input()) ..
๋ฌธ์ œ๋ฐฑ์ค€ ์žƒ์–ด๋ฒ„๋ฆฐ ๊ด„ํ˜ธ https://www.acmicpc.net/problem/1541 ์ฝ”๋“œformular = list(input())formular.append('-')have_to_sum = []have_to_sub = []operand = ''for letter in formular: if letter != '+' and letter != '-': operand += letter elif letter == '+': have_to_sum.append(int(operand)) operand = '' elif letter == '-': have_to_sum.append(int(operand)) have_to_sub.appen..
์˜ค๋ฒ„๋ผ์ด๋”ฉ์ƒ์†์‹œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์Šˆํผํด๋ž˜์Šค์— ์žˆ๋Š” ํ•จ์ˆ˜์™€ ๊ฐ™์€ ์ด๋ฆ„, ํ˜•ํƒœ๋ฅผ ๊ฐ€์ง„ ํ•จ์ˆ˜๋ฅผ ์„œ๋ธŒํด๋ž˜์Šค์—์„œ ์“ธ ์ˆ˜ ์—†๋‹ค.ํ•˜์ง€๋งŒ ์Šˆํผํด๋ž˜์Šค์—์„œ ํ—ˆ์šฉํ•œ๋‹ค๋ฉด ์˜ค๋ฒ„๋ผ์ด๋”ฉ ์ด๋ผ๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ์„œ๋ธŒ ํด๋ž˜์Šค์—์„œ ๊ฐ™์€ ์ด๋ฆ„๊ณผ ํ˜•ํƒœ๋กœ ๋œ ํ•จ์ˆ˜์˜ ๋‚ด์šฉ์„ ๋‹ค์‹œ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ค๋ฒ„๋ผ์ด๋”ฉ ๋ฐฉ๋ฒ•์Šˆํผํด๋ž˜์Šค์˜ ํ•จ์ˆ˜ ์•ž์— open ํ‚ค์›Œ๋“œ๋ฅผ ๋ถ™์ด๋ฉด ์„œ๋ธŒํด๋ž˜์Šค์—์„œ ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ ์„œ๋ธŒํด๋ž˜์Šค์—์„œ ์žฌ๊ตฌํ˜„์ด ํ—ˆ์šฉ๋œ๋‹ค.์„œ๋ธŒํด๋ž˜์Šค์—์„œ ํ•จ์ˆ˜ ์•ž์— override ํ‚ค์›Œ๋“œ๋ฅผ ๋ถ™์ด๋ฉด ์„œ๋ธŒํด๋ž˜์Šค์—์„œ ์žฌ๊ตฌํ˜„ ํ•  ์ˆ˜ ์žˆ๋‹ค.fun main(){ var a = Animal() var t = Tiger() a.eat() t.eat()}open class Animal{ open fun eat(){ println("๋จน์ด ๋ƒ ๋ƒ ") }}c..
์ƒ์†์ด ํ•„์š”ํ•œ ์ด์œ ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ ํ™•์žฅํ•˜์—ฌ ์ƒˆ๋กœ์šด ์†์„ฑ์ด๋‚˜ ํ•จ์ˆ˜๋ฅผ ์ถ”๊ฐ€ํ•œ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ• ๋•Œ์—ฌ๋Ÿฌ๊ฐœ์˜ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์—ˆ๋Š”๋ฐ ํด๋ž˜์Šค์˜ ๊ณตํ†ต์ ์„ ๋ฝ‘์•„ ์ฝ”๋“œ ๊ด€๋ฆฌ๋ฅผ ํŽธํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์•ผ ํ• ๋•Œ ์Šˆํผํด๋ž˜์Šค & ์„œ๋ธŒํด๋ž˜์Šค์†์„ฑ๊ณผ ํ•จ์ˆ˜๋ฅผ ๋ฌผ๋ ค์ฃผ๋Š” ์ชฝ์„ ์Šˆํผํด๋ž˜์Šค, ๋ฌผ๋ ค ๋ฐ›๋Š” ์ชฝ์„ ์„œ๋ธŒ ํด๋ž˜์Šค๋ผ๊ณ  ํ•œ๋‹ค. ์ƒ์† ๋ฐฉ๋ฒ•open ํ‚ค์›Œ๋“œ์ฝ”ํ‹€๋ฆฐ์€ ์ƒ์† ๊ธˆ์ง€๊ฐ€ ๊ธฐ๋ณธ๊ฐ’์ด๊ธฐ ๋•Œ๋ฌธ์— open ํ‚ค์›Œ๋“œ๋ฅผ ์จ์•ผํ•œ๋‹ค.open์€ ํด๋ž˜์Šค๊ฐ€ ์ƒ์† ๋  ์ˆ˜ ์žˆ๋„๋ก ํด๋ž˜์Šค ์„ ์–ธ ์‹œ ๋ถ™์—ฌ์ค„ ์ˆ˜ ์žˆ๋Š” ํ‚ค์›Œ๋“œ๋‹ค. ์ƒ์†์— ๋Œ€ํ•œ ๋‘๊ฐ€์ง€ ๊ทœ์น™์„œ๋ธŒํด๋ž˜์Šค๋Š” ์Šˆํผํด๋ž˜์Šค์— ์กด์žฌํ•˜๋Š” ์†์„ฑ๊ณผ ๊ฐ™์€ ์ด๋ฆ„์˜ ์†์„ฑ์„ ๊ฐ€์งˆ ์ˆ˜ ์—†๋‹ค.Dog ํด๋ž˜์Šค๊ฐ€ Animalํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›์„๋•Œ var์ด๋‚˜ val์„ ๋ถ™์ด์ง€ ์•Š๊ณ  ์ผ๋ฐ˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋ฐ›๋Š”๋‹ค.var ์ด๋‚˜ val์„ ๋ถ™์ด๋ฉด ํด๋ž˜์Šค์˜ ์ž์ฒด ์†์„ฑ์œผ..
์ƒ์„ฑ์ž์˜ ์—ญํ•     ์ƒ์„ฑ์ž๋Š” ์ธ์Šคํ„ด์Šค์˜ ๊ธฐ๋Šฅ์„ ์ดˆ๊ธฐํ™” ํ•˜๊ณ  ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ์‹œ ๊ตฌ๋ฌธ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์—ญํ• ์„ ํ•˜๊ธฐ๋„ ํ•œ๋‹ค. init{}์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด ์ธ์Šคํ„ด์Šค๊ฐ€ ๋งŒ๋“ค์–ด ์งˆ ๋•Œ ํ˜ธ์ถœ๋˜๋Š” ํ•จ์ˆ˜ ๊ธฐ๋ณธ์ƒ์„ฑ์ž & ๋ณด์กฐ์ƒ์„ฑ์ž๊ธฐ๋ณธ ์ƒ์„ฑ์ž : ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค ๋•Œ ๊ธฐ๋ณธ์œผ๋กœ ์„ ์–ธ๋ณด์กฐ ์ƒ์„ฑ์ž : ํ•„์š”์— ๋”ฐ๋ผ ์ถ”๊ฐ€์ ์œผ๋กœ ์„ ์–ธ. ๊ธฐ๋ณธ ์ƒ์„ฑ์ž์™€ ๋‹ค๋ฅธ ํ˜•ํƒœ์˜ ์ƒ์„ฑ์ž๋ฅผ ์ œ๊ณตํ•˜์—ฌ ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ์‹œ ํŽธ์˜๋ฅผ ์ œ๊ณตํ•˜๊ฑฐ๋‚˜ ์ถ”๊ฐ€์ ์ธ ๊ตฌ๋ฌธ์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณต๋ณด์กฐ ์ƒ์„ฑ์ž ์‚ฌ์šฉ ๋ฐฉ๋ฒ•๋ณด์กฐ ์ƒ์„ฑ์ž๋ฅผ ๋งŒ๋“ค๋•Œ๋Š” ๋ฐ˜๋“œ์‹œ ๊ธฐ๋ณธ ์ƒ์„ฑ์ž๋ฅผ ํ†ตํ•ด ์†์„ฑ์„ ์ดˆ๊ธฐํ™” ํ•ด์ค˜์•ผ ํ•œ๋‹ค.๋ณด์กฐ ์ƒ์„ฑ์ž๊ฐ€ ๊ธฐ๋ณธ ์ƒ์„ฑ์ž๋ฅผ ํ˜ธ์ถœํ•˜๋„๋ก ํ•˜๋ ค๋ฉด ":this" ํ‚ค์›Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ๊ธฐ๋ณธ ์ƒ์„œ์ž๊ฐ€ ํ•„์š”๋กœ ํ•˜๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ด„ํ˜ธ์•ˆ์— ๋„ฃ์–ด์ฃผ๋ฉด ๋œ๋‹ค. fun main(){ var younghee = Person..
๋•ก๋•ก๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป
'๋ถ„๋ฅ˜ ์ „์ฒด๋ณด๊ธฐ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก (4 Page)