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
function loadPage(times = 10, interval = 300, callback){ | |
var counter = 0 | |
var interval = setInterval(()=> { | |
counter++; | |
window.scrollTo(0,document.body.scrollHeight); | |
if(callback){ | |
callback(); | |
} | |
if(counter === times){ | |
clearInterval(interval); |
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 application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | |
// Override point for customization after application launch. | |
// notification | |
if let options = launchOptions { | |
let notificationPayload: NSDictionary = options[UIApplicationLaunchOptionsRemoteNotificationKey] as NSDictionary | |
// do somehting with the notifications | |
} | |
// Register for Push Notitications, if running iOS 8 |
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 | |
let numbers = Array(1...1000) | |
func binarySearch<T: Comparable>(_ a: [T], key: T, range:Range<Int>) -> Int?{ | |
if range.lowerBound >= range.upperBound{ return nil} | |
let midIndex = range.lowerBound + (range.upperBound - range.lowerBound)/2 | |
if key < a[midIndex]{ |
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
// swap | |
func insertionSort(_ a:[Int]) -> [Int]{ | |
var array = a | |
for i in 1..<array.count{ | |
var k = i | |
while k>0 && array[k-1] > array[k]{ | |
(array[k-1], array[k]) = (array[k], array[k-1]) | |
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
func selectionSort(_ array: [Int]) -> [Int]{ | |
var a = array | |
for i in 0..<a.count - 1{ | |
var lowest = i | |
for j in i+1..<a.count{ | |
if a[j] < a[lowest]{ | |
lowest = j | |
} | |
} | |
if lowest != i{ |
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 bubbleSort(_ list: [Int]) -> [Int]{ | |
var array = list | |
var swapped = true | |
while swapped{ | |
swapped = false | |
for i in 0..<array.count-1{ | |
if array[i] > array[i+1]{ | |
(array[i], array[i+1]) = (array[i+1], array[i]) |
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 class BinarySearchTree<T:Comparable>{ | |
private(set) public var value: T | |
private(set) public var parent: BinarySearchTree<T>? | |
private(set) public var leftChield: BinarySearchTree<T>? | |
private(set) public var rightChield: BinarySearchTree<T>? | |
public init(value: T){ | |
self.value = value | |
} | |
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 palindrom(_ string: String) -> Bool{ | |
let strippedString = string.replacingOccurrences(of: "\\W", with: "", options: .regularExpression, range: nil) | |
let length = strippedString.characters.count | |
if length == 0 { | |
return true | |
}else if length > 1{ | |
return isPalindrom(strippedString.lowercased(), left: 0, right: length-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
func kthSmallest(_ root: TreeNode?, _ k: Int) -> Int { | |
guard let _ = root else { | |
return -1 | |
} | |
var count = 0 | |
var stack = [TreeNode]() | |
var root = root | |
while !stack.isEmpty || root != nil { |
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 reverseString(_ s: String) -> String { | |
var reversed = "" | |
var stringArray = Array(s.characters) | |
var n = s.characters.count | |
for i in 0..<stringArray.count{ | |
reversed.append(stringArray[n-1-i]) | |
} | |
return reversed | |
} |
OlderNewer