Skip to content

Instantly share code, notes, and snippets.

View antrix1989's full-sized avatar

Sergei Demchenko antrix1989

  • Microsoft
  • Vancouver, BC
View GitHub Profile
#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;
#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
#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
#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
// 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
#import <Foundation/Foundation.h>
@interface NSString (ConvertToArray)
-(NSArray *)convertToArray;
@end
@implementation NSString (ConvertToArray)
-(NSArray *)convertToArray
{
// Implement strStr()
// O(n*m)
@interface NSString (ConvertToArray)
-(NSArray *)convertToArray;
@end
@implementation NSString (ConvertToArray)
-(NSArray *)convertToArray
#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
// 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;
#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;