전체 글(717)
-
Kotlin #3 coroutine
Coroutine서브루틴한번에 하나가 실행됨호출자가 호출하고 결과를 수신코루틴여러 루틴이 동등하게 서로 협력하여 다양한 실행 짖넘에서 동작을 넘기거나 다시 받아올 수 있음경량 동시성 구조실행을 일시 중단하고 재개요즘 언어에서 중요한 패러다임C++20도 지원코루틴 vs. 스레드스레드는 OS 수준에서 관리독자적인 thread stack을 지니고 context switching 시 CPU의 register 값(sp, lr 포함)을 stack에 load/store 수행또한 cache, TLB 등 flush 유발하므로 매우 high cost반면에 코루틴은 언어 수준에서의 문맥전환으로 실제 하나의 스레드 상에서 여러 루틴을 돌아가면서 수행코루틴은 루틴들의 협력협력이란 루틴 스스로 문맥 전환을 수행해야 함을 의미코루..
2026.09.24 -
Kotlin #2
함수fun add(op1: Int, op2: Int): Int { return op1 + op2}fun hello(name: String): Unit { println(name)}단일 표현식 함수= 뒤에 함수 본문 정의fun foo() = println("bar")varargfun func(vararg names: String) { for (name in names) { println(name) }}func("a", "b", "c")명명된 인수fun func(name: String, age: Int) { prinln("$name, $age")}func(name = "a", age = 1)func(age = 2, name = "b")inline functioninli..
2026.09.23 -
Kotlin #1
변수 및 타입mutable / immutableimmutableval message = "hello"val pi = 3.141592mutable variablevar cnt = 1println(cnt) // 1cnt += 1println(cnt) // 2lazy initlazy initializationval msg: String by lazy ( "hello")println(msg) // 여기서 최초로 초기화 println(msg) // 이후 초기화 된 값 사용 lateinitlateinit var msg: Stringif (::msg.isInitialized) { println("not initialized") // 출력됨}msg = "foo"nullable typevar msg..
2026.09.23 -
1791. Find Center of Star Graph
class Solution: def findCenter(self, edges: List[List[int]]) -> int: inbound = collections.defaultdict(int) mx = -1 node = -1 for u, v in edges: inbound[u] += 1 inbound[v] += 1 if inbound[u] > mx: mx = inbound[u] node = u if inbound[v] > mx: mx = inbound[v] node ..
2026.05.10 -
1926. Nearest Exit from Entrance in Maze
class Solution: def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int: sy, sx = entrance q = collections.deque([(sy, sx, 0)]) visited = {(sy, sx)} rows = len(maze) cols = len(maze[0]) while q: y, x, step = q.popleft() if maze[y][x] == '.' and (y == rows - 1 or y == 0 or x == 0 or x == cols - 1) \ ..
2026.05.10 -
1930. Unique Length-3 Palindromic Subsequences
1930. Unique Length-3 Palindromic Subsequences [Unique Length-3 Palindromic Subsequences - LeetCodeCan you solve this real interview question? Unique Length-3 Palindromic Subsequences - Given a string s, return the number of unique palindromes of length three that are a subsequence of s. Note that even if there are multiple ways to obtain the same subseleetcode.com](https://leetcode.com/problems..
2026.05.10