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
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 |
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
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) }) }) |
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 | |
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 |
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
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) |
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
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) |
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
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"` | |
// автор |
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
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] | |
} |
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
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, |
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 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() |
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
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) |
OlderNewer