This file contains hidden or 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
lazy var v1:UIView = { | |
let v = UIView() | |
v.backgroundColor = .blueColor() | |
return v | |
}() | |
lazy var v2:UIView = { | |
let v = UIView() | |
v.backgroundColor = .blueColor() | |
return v |
This file contains hidden or 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
let sampleTextField = UITextField(frame: CGRectMake(20, 100, 300, 40)) | |
sampleTextField.placeholder = "Enter text here" | |
sampleTextField.font = UIFont.systemFontOfSize(15) | |
sampleTextField.borderStyle = UITextBorderStyle.RoundedRect | |
sampleTextField.autocorrectionType = UITextAutocorrectionType.No | |
sampleTextField.keyboardType = UIKeyboardType.Default | |
sampleTextField.returnKeyType = UIReturnKeyType.Done | |
sampleTextField.clearButtonMode = UITextFieldViewMode.WhileEditing; | |
sampleTextField.contentVerticalAlignment = UIControlContentVerticalAlignment.Center | |
sampleTextField.delegate = self |
This file contains hidden or 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 quickSort<T:Comparable>(_ list:[T])->[T]{ | |
if list.count == 0 { | |
return [] | |
} | |
let pivot = list[list.count/2] | |
let equal = list.filter{ $0 == pivot } | |
let less = list.filter{ $0 < pivot } | |
let greater = list.filter{ $0 > pivot } | |
return quickSort(less) + equal + quickSort(greater) | |
} |
This file contains hidden or 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 Contacts | |
func createContact()->CNMutableContact{ | |
let contact = CNMutableContact() | |
contact.namePrefix = "John" | |
contact.nameSuffix = "Applesee" | |
contact.organizationName = "Apple" | |
contact.jobTitle = "Software Engineer" | |
This file contains hidden or 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 | |
/* | |
1108. Defanging an IP Address | |
Given a valid (IPv4) IP address, return a defanged version of that IP address. | |
A defanged IP address replaces every period "." with "[.]". | |
Example 1: |
This file contains hidden or 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 App { | |
public static void main(String[] args) { | |
int[] array = {5,9,1,8,2,7,3,6,4}; | |
System.out.println("original " + array); | |
bubbleSort(array); | |
System.out.println("sorted " + array); | |
} | |
private static void bubbleSort(int[] array) { | |
boolean swapped; | |
int n = array.length; |
OlderNewer