Skip to content

Instantly share code, notes, and snippets.

View WhiteHyun's full-sized avatar

SeungHyun Hong WhiteHyun

View GitHub Profile
@WhiteHyun
WhiteHyun / 300. Longest Increasing Subsequence.swift
Created July 19, 2024 19:49
LeetCode - 300. Longest Increasing Subsequence using Greedy & Binary Search
final class Solution {
func lengthOfLIS(_ nums: [Int]) -> Int {
var tails: [Int] = [nums[0]]
for index in 1 ..< nums.count {
if nums[index] > tails.last! {
tails.append(nums[index])
} else {
tails[binarySearch(tails, target: nums[index])] = nums[index]
@WhiteHyun
WhiteHyun / 300. Longest Increasing Subsequence.swift
Created July 19, 2024 19:09
LeetCode - 300. Longest Increasing Subsequence using DP
final class Solution {
func lengthOfLIS(_ nums: [Int]) -> Int {
var dp: [Int] = .init(repeating: 1, count: nums.count)
for i in 1..<nums.count {
for j in 0..<i where dp[i] <= dp[j] && nums[j] < nums[i] {
dp[i] = dp[j] + 1
}
}
@WhiteHyun
WhiteHyun / main.swift
Created June 18, 2024 07:12
Vapor with APIProtocol
import Foundation
import Vapor
import OpenAPIRuntime
import OpenAPIVapor
struct GreetingService: APIProtocol {
func getGreeting(_ input: Operations.getGreeting.Input) async throws -> Operations.getGreeting.Output {
let name = input.query.name ?? "Stranger"
let greeting = Components.Schemas.Greeting(message: "Hello, \(name)!")
return .ok(.init(body: .json(greeting)))
@WhiteHyun
WhiteHyun / main.swift
Created June 18, 2024 06:27
Vapor - basic execution
import Vapor
let app = Application()
try app.run()
@WhiteHyun
WhiteHyun / openapi.yaml
Last active June 18, 2024 06:12
OpenAPI yaml
openapi: "3.1.0"
info:
title: "App"
version: "1.0.0"
servers:
- url: "https://api.path.com/v1"
description: "Production Server"
- url: "https://localhost/v1"
description: "Internal staging server for testing"
@WhiteHyun
WhiteHyun / Package.swift
Created June 18, 2024 05:20
OpenAPI Generator Server
// swift-tools-version: 5.10
import PackageDescription
let package = Package(
name: "OpenAPIService",
platforms: [
.macOS(.v14),
],
dependencies: [
// Author: SwiftUI-Lab (www.swiftui-lab.com)
// Description: This code is part of the "Advanced SwiftUI Animations - Part 5"
// Article: https://swiftui-lab.com/swiftui-animations-part5/
import SwiftUI
struct ContentView: View {
var body: some View {
ClockView()
.background(.gray)
@WhiteHyun
WhiteHyun / Queue.swift
Created September 5, 2023 04:52
Swift Queue
struct Queue<Element> {
private var frontArray: [Element] = []
private var backArray: [Element] = []
mutating func append(_ element: Element) {
backArray.append(element)
}
mutating func popFirst() -> Element? {
if !frontArray.isEmpty { return frontArray.popLast() }
@WhiteHyun
WhiteHyun / 합승 택시 요금.swift
Last active August 21, 2023 13:40
프로그래머스 - 합승 택시 요금 (Swift)
/// 합승 택시 요금 문제 풀이
struct Number72413 {
/// 합승 택시 요금 문제 풀이
/// - Parameters:
/// - n: 지점의 개수
/// - startNumber: 시작 정점
/// - a: A의 목표 정점
/// - b: B의 목표 정점
@WhiteHyun
WhiteHyun / 미로 탈출 명령어.swift
Created August 16, 2023 02:31
프로그래머스 - 미로 탈출 명령어 (Swift)
//
// 미로 탈출 명령어
// https://school.programmers.co.kr/learn/courses/30/lessons/150365
//
// Created by whitehyun on 2023/08/15.
//
import Foundation
struct Queue<Element> {