This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// Layout | |
// | |
// Created by Yu Yu on 2022/8/21. | |
// | |
import SwiftUI | |
struct ContentView: View { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
import struct Foundation.UUID | |
extension UUID { | |
internal init(_ uint8s: UInt8...) { | |
var list:[UInt8] = Array(repeating: 0, count: 16) | |
for (index, value) in uint8s.enumerated() where index < 16 { | |
list[15-index] = value | |
} | |
self.init(list: list) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import XCTest | |
final class DecodeTests: XCTestCase { | |
func testMeta1() throws { | |
let rawJson = | |
""" | |
{ | |
"a1": { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class FibTests: XCTestCase { | |
class DPO1 { | |
func fib(_ n: Int) -> Int { | |
var dp = [0,1] | |
if n < 2 {return dp[n]} | |
for i in 2...n { | |
dp[i&1] = dp[0] + dp[1] | |
} | |
return dp[n&1] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public class TreeNode { | |
public var val: Int | |
public var left: TreeNode? | |
public var right: TreeNode? | |
public init() { self.val = 0; self.left = nil; self.right = nil; } | |
public init(_ val: Int) { self.val = val; self.left = nil; self.right = nil; } | |
public init(_ val: Int, _ left: TreeNode?, _ right: TreeNode?) { | |
self.val = val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class SolutionDP1 { | |
// DP | |
public func splitArray(_ nums: [Int],_ m: Int) -> Int { | |
let n = nums.count | |
/** | |
``` | |
dp [n+1:2] | |
[ | |
min, max, max, .... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
/// https://leetcode.com/problems/container-with-most-water/ | |
private class Solution { | |
/// Area = d * h | |
/// which | |
/// d === i - j | |
/// h === min(Ai, Aj) | |
/// whatever pair of i, j, tallest one is more possible to have greater value | |
/// so that will move the shorter one to the center | |
/// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
/* | |
* Created by 游宗諭 in 2021/9/2 | |
* | |
* Using Swift 5.0 | |
* | |
* Running on macOS 12.0 | |
*/ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
@testable import DataCutter | |
@propertyWrapper struct Byte<Value>: ByteDecode { | |
func decodeValue(from data: Data) throws { | |
let value = data | |
.subdata(in: inner.range) | |
.withUnsafeBytes { $0.load(as: Value.self) } | |
inner.value = .already(value) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - EqualKeyPath | |
struct EqualKeyPath<T, A> where A: Equatable { | |
init(on: T.Type, for k1: KeyPath<T, A>) { | |
self.k1 = k1 | |
} | |
let k1: KeyPath<T, A> | |
func equalFor(_ a: T, _ b: T) -> Bool { | |
a[keyPath: k1] == b[keyPath: k1] |
NewerOlder