Skip to content

Instantly share code, notes, and snippets.

View GregoryMaks's full-sized avatar

Gregory Maksiuk GregoryMaks

View GitHub Profile
class Solution {
func removePalindromeSub(_ s: String) -> Int {
guard s.count > 0 else { return 0 }
if isPalindrome(s) { return 1 }
return 2
}
private func isPalindrome(_ s: String) -> Bool {
let b = "b".utf8CString[0]
// Time: O(NxK)
// Space: O(NxK) - need to store the results somewhere
class Solution {
func mergeKLists(_ lists: [ListNode?]) -> ListNode? {
var tops = lists.compactMap { $0 ?? nil }
var resultRoot: ListNode?
var resultLast: ListNode?
while tops.count > 0 {
var pickIdx = 0
var val = Int.max
// Time: O(MxN*3^L)
// Space: O(L), don't count matrix change
class Solution {
let dt: [[Int]] = [[0, 1], [0, -1], [1, 0], [-1, 0]]
func exist(_ board: [[Character]], _ word: String) -> Bool {
var board = board
let word: [Character] = Array(word)
var locs: [[Int]] = []
class Solution {
func networkDelayTime(_ times: [[Int]], _ n: Int, _ k: Int) -> Int {
var graph: [Int: [(Int, Int)]] = [:]
for time in times {
var edges = graph[time[0]] ?? []
edges.append((time[1], time[2]))
graph[time[0]] = edges
}
struct HeapNode: Comparable {
@GregoryMaks
GregoryMaks / RunningApplicationsObserver.swift
Created August 1, 2023 10:32
Observes current running applications through `NSWorkspace` and notifies if any of the requested applications change their running status
import AppKit
import Combine
import CombineExt
import Foundation
import SharedUtils
// sourcery: Automockable
protocol RunningApplicationsObserverType {
func observeApplicationsRunningStatus(bundleIdentifiers: [String]) -> AnyPublisher<Void, Never>
}
@GregoryMaks
GregoryMaks / fileExtensionsForUTType.swift
Created February 16, 2022 17:29
File extensions for specified UTType and all its descenders
import UniformTypeIdentifiers
let allTypes: [UTType] = [
.item,
.content,
.compositeContent,
.diskImage,
.data,
.directory,
@GregoryMaks
GregoryMaks / enable-xcode-debug-menu.sh
Created February 23, 2020 13:05 — forked from dsabanin/enable-xcode-debug-menu.sh
Enable internal Xcode debug menu in Xcode 11
defaults write com.apple.dt.Xcode ShowDVTDebugMenu -bool YES
sudo mkdir -p /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode
sudo touch /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode/AppleInternal.plist
# Don't forget to restart Xcode
@GregoryMaks
GregoryMaks / used-macbook-cheatsheet.md
Last active October 19, 2023 10:11
Buying used Macbook?
static func from(serverModel: DoctorCustomRulesServerModel) -> Rules? {
guard let motherRule = serverModel.rules.first(where: { $0.subjectType == .mHR }),
let fetusRule = serverModel.rules.first(where: { $0.subjectType == .fHR })
else {
return nil
}
return Rules(
fetalNormalRangeMin: fetusRule.normalCurrentRangeFrom,
fetalNormalRangeMax: fetusRule.normalCurrentRangeTo,
static func from(serverModel: DoctorCustomRulesServerModel) -> Rules? {
guard let motherRule = serverModel.rules.first(where: { $0.subjectType == .mHR }),
let fetusRule = serverModel.rules.first(where: { $0.subjectType == .fHR })
else {
return nil
}
return Rules(
fetalNormalRangeMin: fetusRule.normalCurrentRangeFrom,
fetalNormalRangeMax: fetusRule.normalCurrentRangeTo,