This file contains 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 java.io.*; | |
import java.util.*; | |
/** | |
* https://class.coursera.org/algo/quiz/attempt?quiz_id=52 | |
*/ | |
public class MinCut { | |
private static class Graph { | |
This file contains 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> | |
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; |
This file contains 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
#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; |
This file contains 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<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(); |
This file contains 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> | |
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++) { |
This file contains 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> | |
using namespace std; | |
class Node { | |
public: | |
int data; | |
Node *next; | |
Node(int dat) { | |
data = dat; | |
next = NULL; |
This file contains 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<set> | |
using namespace std; | |
class Node { | |
public: | |
int data; | |
Node *next; | |
Node(int dat) { | |
data = dat; |
This file contains 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
#!/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) |
This file contains 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
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 |
This file contains 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
// 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 | |
* |
OlderNewer