Skip to content

Instantly share code, notes, and snippets.

View honghaoz's full-sized avatar
:shipit:
shipit

HongHao Zhang honghaoz

:shipit:
shipit
View GitHub Profile
import java.io.*;
import java.util.*;
/**
* https://class.coursera.org/algo/quiz/attempt?quiz_id=52
*/
public class MinCut {
private static class Graph {
@honghaoz
honghaoz / String-ReverseString.cpp
Last active August 29, 2015 14:02
ReverseAString
#include<iostream>
using namespace std;
void reverse(char a[]) {
int length = strlen(a);
char temp;
for (int i = 0; i < length / 2; i++) {
temp = a[i];
a[i] = a[length - 1 - i];
a[length - 1 - i] = temp;
@honghaoz
honghaoz / String-CheckUniqueCharacters.cpp
Last active August 29, 2015 14:02
Check whether characters are unique in a string
#inlcude <cstring>
#include <iostream>
#include <set>
#include <cstring>
using namespace std;
bool checkUniqueChars(char *str) {
char *strP = str;
set<char> testSet;
pair<set<char>::iterator, bool> result;
@honghaoz
honghaoz / String-SamePermutation.cpp
Last active August 29, 2015 14:02
Check whether one string is a permutation of the other
include<set>
include<cstring>
using namespace std;
bool checkSame(string a, string b) {
if (a.length() != b.length()) {
return false;
}
map<char, int> testMap;
int length = (int)a.length();
@honghaoz
honghaoz / Sort-CountSort.cpp
Last active August 29, 2015 14:02
CountSort
#include<iostream>
using namespace std;
void countSort(int a[], int size, int k) {
int *b = (int *)malloc(sizeof(int) * k);
memset(b, 0, sizeof(int) * k);
for (int i = 0; i < size; i++) {
b[a[i]]++;
}
for (int i = 1; i < k; i++) {
@honghaoz
honghaoz / LinkedList-Basics.cpp
Last active August 29, 2015 14:02
LinkedList Basic definitions and operations
#include<iostream>
using namespace std;
class Node {
public:
int data;
Node *next;
Node(int dat) {
data = dat;
next = NULL;
@honghaoz
honghaoz / LinkedList-RemoveDuplicates.cpp
Created June 6, 2014 01:57
Remove duplicates from an unsorted linked list
#include<iostream>
#include<set>
using namespace std;
class Node {
public:
int data;
Node *next;
Node(int dat) {
data = dat;
#!/usr/bin/env python
from random import randint
from copy import deepcopy
def find_mincut(n, e):
mincut = len(e)
N = 2000
for x in range(N):
nodes = deepcopy(n)
@honghaoz
honghaoz / isPrime.py
Last active August 29, 2015 14:06
isPrime
def isPrime(n):
'''check if integer n is a prime'''
# make sure n is a positive integer
n = abs(int(n))
# 0 and 1 are not primes
if n < 2:
return False
# 2 is the only even prime number
if n == 2:
return True
@honghaoz
honghaoz / collection view perform batch update
Last active August 29, 2015 14:11
collection view perform batch update
// Compare old data model with new data model and perform batch update for collection view
/**
* Perform batch update on collection view, use old stories and new stories to make comparison
* groupId property of story is used for comparison
*
* PRE: make sure collection view's data model is update with newArray
*
* After animation completed, visible cells' view are updated
*