Skip to content

Instantly share code, notes, and snippets.

func absolutePermutation(n: Int, k: Int) -> String {
let r = (1...n)
var tmp = Set<Int>()
var res = ""
for i in r {
var a = i + k
var b = i - k
struct Matrix: CustomStringConvertible {
private var values = [[Int]]()
private var indices = [[(Int, Int)]]()
private let N: Int
private let M: Int
init(lines: [String]) {
let rows = lines.map({ $0.split(separator: " ", maxSplits: Int.max, omittingEmptySubsequences: true).flatMap({ Int($0) }) })
import Foundation
func mult(a: [UInt16], b: [UInt16]) -> [UInt16] {
var c = [UInt16]()
for (i, x) in b.reversed().enumerated() {
var r = UInt16(0)
for (j, y) in a.reversed().enumerated() {
let k = i + j
class Solution {
func myAtoi(_ str: String) -> Int {
var value = 0
var hasValue = false
var isNegative = false
let max = (1 << 31) - 1
let min = -(1 << 31)
@geor-kasapidi
geor-kasapidi / Diff.swift
Created February 27, 2020 19:45
Diff example
public protocol Diffable: Equatable {
var diffId: String { get }
}
public enum Diff {
public enum Change: Hashable {
public typealias Index = Int
case delete(Index)
case insert(Index)
type Blog_LastArticle struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// id статьи
Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
// название
Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"`
// автор
class Solution {
private func prefix(length: Int, char: (Int) -> Character?) -> [Int] {
var p: [Int] = Array(repeating: 0, count: length)
for i in 1..<length {
var k = p[i-1]
while k > 0 && char(i) != char(k) {
k = p[k-1]
}
type LRUCache struct {
capacity int
cache map[int]int
priority *list.List
key2node map[int]*list.Element
}
func Constructor(capacity int) LRUCache {
return LRUCache{
capacity: capacity,
import SwiftUI
/*
Rectangle().fill(Color.green).frame(width: 100, height: 30).badge {
Text("100").foregroundColor(Color.white).padding(8)
}
*/
extension View {
func badge<Content: View>(@ViewBuilder content: () -> Content) -> some View {
let badgeContent = content()
extension UIViewController {
func presentUniqueViewControllerIfNotPresented<T: UIViewController>(_ viewControllerToPresent: () -> T, animated: Bool, completion: (() -> Void)?) {
var presentationHost: UIViewController = self
for viewController in sequence(first: presentationHost, next: { $0.presentedViewController }) {
if viewController is T {
return
}
presentationHost = viewController
}
presentationHost.present(viewControllerToPresent(), animated: animated, completion: completion)