Skip to content

Instantly share code, notes, and snippets.

View nyan-lin-tun's full-sized avatar
🎯
Focusing

Nyan Lin Tun nyan-lin-tun

🎯
Focusing
View GitHub Profile
@nyan-lin-tun
nyan-lin-tun / Leetcode3607.swift
Created November 7, 2025 00:05
Power Grid Maintenance
struct Heap<T> {
private var elements: [T] = []
private let isLess: (T, T) -> Bool
init(_ isLess: @escaping (T, T) -> Bool) {
self.isLess = isLess
}
var isEmpty: Bool { elements.isEmpty }
@nyan-lin-tun
nyan-lin-tun / Leetcode3321.swift
Created November 6, 2025 02:41
Find X-Sum of All K-Long Subarrays II
struct Heap<T> {
private var elements: [T] = []
private let isLess: (T, T) -> Bool
init(_ isLess: @escaping(T, T) -> Bool) {
self.isLess = isLess
}
func peek() -> T? {
elements.first
@nyan-lin-tun
nyan-lin-tun / keybase.md
Last active July 15, 2025 04:29
keybase.md

Keybase proof

I hereby claim:

  • I am nyan-lin-tun on github.
  • I am nyanlintun (https://keybase.io/nyanlintun) on keybase.
  • I have a public key whose fingerprint is A25E 415D BE0A 100E 7405 09E9 56ED AD1A 3425 AB82

To claim this, I am signing this object:

@nyan-lin-tun
nyan-lin-tun / Performance.swift
Created July 3, 2025 13:14
Performance comparison between Array index and index(_, offsetBy: _)
import Foundation
let word = String(repeating: "abcde", count: 200_000) // 1,000,000 characters
let k = 999_999 // Access near the end
// MARK: - String.Index approach
let startIndexMethod = CFAbsoluteTimeGetCurrent()
let index = word.index(word.startIndex, offsetBy: k)
let charFromIndex = word[index]
let endIndexMethod = CFAbsoluteTimeGetCurrent()