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
| class PendingOperations { | |
| lazy var downloadsInProgress: [IndexPath: Operation] = [:] | |
| lazy var downloadQueue: OperationQueue = { | |
| var queue = OperationQueue() | |
| queue.name = "Download queue" | |
| queue.maxConcurrentOperationCount = 1 | |
| return queue | |
| }() | |
| } |
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 UIKit | |
| enum ImageRecordState { | |
| case new, downloaded, failed | |
| } | |
| class ImageRecord { | |
| let name: String | |
| let url: URL | |
| var state = ImageRecordState.new |
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
| -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
| NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:obj.img]]; | |
| dispatch_async(dispatch_get_main_queue(), ^{ | |
| cell.imgView.image = [UIImage imageWithData:imageData]; | |
| }); | |
| return cell; | |
| } |
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
| NSData * imageData = [[NSData alloc] initWithContentsOfURL:url]; UIImage *image = [[UIImage alloc] initWithData:imageData]; | |
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 sortedSquares(arr: [Int]) -> [Int] { | |
| var result = Array(repeating: 0, count: arr.count) | |
| var low = 0 | |
| var high = arr.count-1 | |
| for p in 0..<arr.count { | |
| if arr[low] * arr[low] > arr[high] * arr[high] { | |
| result[p] = arr[low] * arr[low] |
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 sortArrayByParityII(_ A: [Int]) -> [Int] { | |
| var even: [Int] = [] | |
| var odd: [Int] = [] | |
| var result: [Int] = [] | |
| for element in A { | |
| if(element % 2 == 0) { | |
| even.append(element) | |
| } else { | |
| odd.append(element) | |
| } |
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
| class Solution { | |
| func searchBST(_ root: TreeNode?, _ val: Int) -> TreeNode? { | |
| guard let node = root else { return nil } | |
| if node.val == val { return root } | |
| if node.val > val { return searchBST(node.left, val) } | |
| if node.val < val { return searchBST(node.right, val) } | |
| return nil |
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 dividingNumber(_ left: Int, _ right: Int) -> [Int] { | |
| var nums = [Int]() | |
| for i in left...right { | |
| if divisible(i) { | |
| nums.append(i) | |
| } | |
| } | |
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 maximumSwap(number: Int) { | |
| if number == 0 { | |
| return | |
| } | |
| var digits = digitsFromNum(num: number) | |
| var max_index = 0 | |
| var left = 0 | |
| var right = 0 |
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
| Check if A[i] == A[i - 1] or A[i] == A[i - 2] | |
| If so, we return A[i] | |
| If not, it must be [x, x, y, z] or [x, y, z, x]. | |
| We return A[0] for the cases that we miss. | |
| O(N) time O(1) space | |
| class Solution { | |
| func repeatedNTimesIII(_ A: [Int]) -> Int { | |
| for i in 2..<A.count { |