{{ message }}

Instantly share code, notes, and snippets.

# Anil T V aniltv06

Created Feb 28, 2021
Max Consecutive Ones
View MaxConsecutiveOnes.swift
 /* Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3. Note:
Created Feb 28, 2021
Rotate Array
View RotateArray.swift
 /*Given an array, rotate the array to the right by k steps, where k is non-negative. Follow up: Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem. Could you do it in-place with O(1) extra space? Example 1:
Created Apr 4, 2019
Textfield with image placeholder
View DesignableUITextField.swift
 import UIKit @IBDesignable class DesignableUITextField: UITextField { // Provides left padding for images override func leftViewRect(forBounds bounds: CGRect) -> CGRect { var textRect = super.leftViewRect(forBounds: bounds) textRect.origin.x += leftPadding return textRect
Created Jan 2, 2019
Sudoku
View Sudoku.swift
 //: Playground - noun: a place where people can play import UIKit var str = "Hello, playground" /// A Mark is an value in the range 1...9 /// /// An assertion failure will be triggered if an attempt is made
Created Aug 22, 2018
Binary search written in swift
View BinarySearch.swift
 func binarySearch(_ a: [T], key: T, range: Range) -> Int? { if range.lowerBound >= range.upperBound { // If we get here, then the search key is not present in the array. return nil } else { // Calculate where to split the array. let midIndex = range.lowerBound + (range.upperBound - range.lowerBound) / 2 // Is the search key in the left half?
Created Aug 22, 2018
Find LCM and GCD, written in swift
View LCM.swift
 /* Returns the Greatest Common Divisor of two numbers. */ func gcd(_ x: Int, _ y: Int) -> Int { var a = 0 var b = max(x, y) var r = min(x, y) while r != 0 { a = b
Created May 4, 2018