Skip to content

Instantly share code, notes, and snippets.

View MickhailP's full-sized avatar
🎯
Focusing on a issue

Mikhail Perevozchikov MickhailP

🎯
Focusing on a issue
View GitHub Profile
@MickhailP
MickhailP / RotateArray.swift
Created November 22, 2022 20:01
RotateArray
//Given an array, rotate the array to the right by k steps, where k is non-negative.
// Input: nums = [1,2,3,4,5,6,7], k = 3
// Output: [5,6,7,1,2,3,4]
// Explanation:
// rotate 1 steps to the right: [7,1,2,3,4,5,6]
// rotate 2 steps to the right: [6,7,1,2,3,4,5]
// rotate 3 steps to the right: [5,6,7,1,2,3,4]
//SOLUTION:
@MickhailP
MickhailP / BinarySearch.swift
Created November 21, 2022 16:36
BinarySearch
import Foundation
func binarySearch(searchArray: [Int],target: Int, lower: Int, upper: Int) -> Int? {
if lower > upper {
return nil
} else {
var middle = (lower + upper) / 2
print(middle)
if searchArray[middle] == target {
@MickhailP
MickhailP / MergeSort.swift
Last active July 3, 2023 09:49
MergeSort
import Foundation
/*
Array's `Element` type is defined as a generic type parameter `T` that conforms to `Comparable`
*/
func mergesort<T: Comparable>(_ array: [T]) -> [T] {
// If the list has zero or one values, there's nothing to sort, so we return it as-is
if array.count <= 1 { return array }
// At this point the algorithm is in the recursive portion
@MickhailP
MickhailP / NetworkingError.swift
Created November 9, 2022 20:15
NetworkingError
import Foundation
enum NetworkingError: Int, Error, LocalizedError {
// 100 Informational
case `continue` = 100
case switchingProtocols = 101
case processing = 102
case earlyHints = 103
@MickhailP
MickhailP / ImageSaver.swift
Created November 8, 2022 16:54
ImageSaver
import UIKit
class ImageSaver: NSObject {
var succesHandler: (() -> Void)?
var errorHandler: ((Error) -> Void)?
func writeToPhotoAlbum(image: UIImage) {
UIImageWriteToSavedPhotosAlbum(image, self, #selector(saveCompleted), nil)
}
@objc func saveCompleted(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
@MickhailP
MickhailP / HexadecimalColor.swift
Created November 4, 2022 17:49
HexadecimalColor
import SwiftUI
extension Color {
init?(hex: String) {
var hexSanitized = hex.trimmingCharacters(in: .whitespacesAndNewlines)
hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")
var rgb: UInt64 = 0
var red: CGFloat = 0.0