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/Foundation.h> | |
| //Given a linked list, swap every two adjacent nodes and return its head. | |
| //For example, | |
| //Given 1->2->3->4, you should return the list as 2->1->4->3. | |
| //Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed. | |
| // 6:03 PM | |
| @interface Node: NSObject | |
| @property (nonatomic) Node *nextNode; |
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/Foundation.h> | |
| // Merge Two Sorted Lists. | |
| // 1 -> 2 -> 3 -> 4 | |
| // 5 -> 6 -> 7 | |
| @interface Node: NSObject | |
| @property (nonatomic) Node *nextNode; | |
| @property (nonatomic) NSString *value; | |
| @end |
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/Foundation.h> | |
| // Given a linked list, determine if it has a cycle in it. | |
| // 1 -> 2 -> 3 -> 4 | |
| @interface Node: NSObject | |
| @property (nonatomic) Node *nextNode; | |
| @property (nonatomic) NSString *value; | |
| @end |
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/Foundation.h> | |
| // Reverse a singly linked list. | |
| // 1 -> 2 -> 3 -> 4 | |
| @interface Node: NSObject | |
| @property (nonatomic) Node *nextNode; | |
| @property (nonatomic) NSString *value; | |
| @end |
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
| // Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. | |
| // 1 -> 2 -> 3 -> 4 | |
| @interface Node: NSObject | |
| @property (nonatomic) Node *nextNode; | |
| @property (nonatomic) NSString *value; | |
| @end | |
| @implementation Node | |
| @end |
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/Foundation.h> | |
| @interface NSString (ConvertToArray) | |
| -(NSArray *)convertToArray; | |
| @end | |
| @implementation NSString (ConvertToArray) | |
| -(NSArray *)convertToArray | |
| { |
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
| // Implement strStr() | |
| // O(n*m) | |
| @interface NSString (ConvertToArray) | |
| -(NSArray *)convertToArray; | |
| @end | |
| @implementation NSString (ConvertToArray) | |
| -(NSArray *)convertToArray |
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/Foundation.h> | |
| // Anagram | |
| // Given two strings s and t, write a function to determine if t is an anagram of s. | |
| // 8:30 PM | |
| @interface NSString (ConvertToArray) | |
| -(NSArray *)convertToArray; | |
| @end |
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
| // 3 Sum | |
| // You may assume that each input would have exactly one solution, and you may not use the same element twice. | |
| void print3sum(NSMutableArray *array, NSNumber *number) | |
| { | |
| if (array.count < 3) return; | |
| for (int i = 0; i < array.count - 2; i++) { // 0 | |
| int l = i + 1; // 1 | |
| int r = array.count - 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
| #import <Foundation/Foundation.h> | |
| // Two Sum | |
| // You may assume that each input would have exactly one solution, and you may not use the same element twice. | |
| void print2sum(NSMutableArray *array, NSNumber *number) | |
| { | |
| if (array.count <= 1) return; | |
| int l = 0; |