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
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 | |
} |
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 singleNumber(_ nums: [Int]) -> Int { | |
var result:Int = 0 | |
for value in nums{ | |
result ^= value | |
} | |
return result | |
} |
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 moveZeroes(_ nums: inout [Int]) { | |
var numZerosSeen = 0 | |
for (index, val) in nums.enumerated(){ | |
if val == 0{ | |
nums.remove(at: index-numZerosSeen) | |
nums.append(0) | |
numZerosSeen += 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 twoSum(_ array:[Int], _ sum: Int) -> (Int,Int)?{ | |
var dic = [Int: Int]() | |
for i in 0..<array.count{ | |
let complement = sum - array[i] | |
if dic[complement] != nil{ | |
return (i, dic[complement]!) | |
} | |
dic[array[i]] = i | |
} | |
return 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
public struct Queue<T>{ | |
private var array = [T]() | |
public mutating func enqueue(_ item: T){ | |
array.append(item) | |
} | |
public mutating func dequeue() -> T?{ | |
if isEmpty{ | |
return nil |
OlderNewer