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
| // Find the lowest number of days that will require to update all the serves on the grid. | |
| // Where every server with the value of 1 is updated and can update any other server that is above, below, next or previous. | |
| // A server that requires an update is represented by 0 value and an updated server is represented by 1 value. | |
| // Any server that needs to be updated will take 1 day to update. | |
| // sameple grid -- result should be 3 | |
| let grid: [[Int]] = [[0, 1, 1, 1], | |
| [1, 1, 0, 1], | |
| [1, 1, 1, 1], | |
| [1, 0, 1, 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
| NSLog(@"\n\n***************\n\n"); | |
| // creating and accessing stored cookies | |
| NSHTTPCookie *cookie; | |
| NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; | |
| // looping over all stored cookies & printing the relevant content | |
| for (cookie in [cookieJar cookies]) { | |
| NSLog(@"\n\n%@", cookie); | |
| NSLog(@"name: %@", cookie.name); |
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 getTimeFromString(timeStr: String, timeZoneStr: String) -> String { | |
| if(!timeStr.isEmpty && !timeZoneStr.isEmpty) { | |
| let dateFormatter = NSDateFormatter() | |
| dateFormatter.dateFormat = "EEE, d MMM yyyy HH:mm:ss Z" | |
| dateFormatter.timeZone = NSTimeZone(name: timeZoneStr) | |
| let date: NSDate = dateFormatter.dateFromString(timeStr)! | |
| let formatter = NSDateFormatter() | |
| formatter.timeStyle = .ShortStyle |
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
| - (NSNumber *)firstUniqueNumberFromArray:(NSArray *)array | |
| { | |
| // if there is no list we return nil | |
| if(!array || array.count == 0) | |
| return nil; | |
| NSNumber *number; | |
| // if there is 1 number in the list or is there 2 numbers and they are not equal then we return the first number from the list | |
| if(array.count == 1 || (array.count == 2 && [[array objectAtIndex:0] longValue] != [[array objectAtIndex:1] longValue])) |
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
| #pragma mark - Merge Sort | |
| - (NSMutableArray *)mergeSorting:(NSMutableArray *)array | |
| { | |
| if(array.count == 1 || !array) | |
| return array; | |
| NSMutableArray *firstHalfArr = [self splitFirstHalfOfArray:array]; | |
| NSMutableArray *secondHalfArr = [self splitSecondHalfOfArra:array]; | |
| firstHalfArr = [self mergeSorting:firstHalfArr]; |
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
| // quicksort implementation | |
| - (NSMutableArray *)quickSorting:(NSMutableArray *)array withLow:(int)low andHigh:(int)high | |
| { | |
| if(array) | |
| { | |
| if(low < high) | |
| { | |
| int pivot_location = [self partitionArray:array withLow:low andHigh:high]; | |
| [self quickSorting:array withLow:low andHigh:(pivot_location)]; | |
| [self quickSorting:array withLow:(pivot_location + 1) andHigh:high]; |
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
| /* | |
| * Helper function to find the number that only occurs once in our list | |
| * @param, receives a list as a NSArray | |
| * @return, returns the number that occours once in the array | |
| */ | |
| - (NSNumber *)firstUniqueNumberFromArray:(NSArray *)array | |
| { | |
| // first we need to declare our return type. | |
| NSNumber *onceNum; | |
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
| #include <iostream> | |
| #include <list> | |
| #include <vector> | |
| #include <string> | |
| #include <algorithm> | |
| using namespace std; | |
| int const SIZE = 5; |
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
| #include <iostream> | |
| #include <algorithm> | |
| using namespace std; | |
| const int SIZE = 5; | |
| class Node { | |
| int _data; | |
| Node *_next; |
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
| #include <iostream> | |
| #include <list> | |
| #include <algorithm> | |
| using namespace std; | |
| const int SIZE = 5; | |
| int main(int argc, const char * argv[]) { | |
| // insert code here... |
NewerOlder