Skip to content

Instantly share code, notes, and snippets.

@sturgle
sturgle / reverseLinkList.cpp
Created December 13, 2014 17:30
reverse a linked list with array as member
@sturgle
sturgle / bintree_iterator.cpp
Last active August 29, 2015 14:11
Binary tree iterator
#include <iostream>
#include <stack>
using namespace std;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int _val) : val(_val), left(NULL), right(NULL) {};
};
@sturgle
sturgle / readN.cpp
Last active August 29, 2015 14:09
use readM to implement readN
#include <iostream>
#include <sstream>
using namespace std;
// ******************** m reader mocker *********************
string inputstr;
void initInputStr() {
string line;
#include <vector>
#include <algorithm>
using namespace std;
struct Road {
int start;
int end;
int val;
};
@sturgle
sturgle / buildBstFromPreOrder.cpp
Created October 27, 2014 04:06
build bst from pre order array
#include <vector>
#include <stack>
#include <iostream>
using namespace std;
struct ListNode {
int val;
ListNode *left;
ListNode *right;
ListNode(int _val) : val(_val), left(NULL), right(NULL) {}
/*
by cpcs
*/
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
//248_next_min_number.cpp
// by cydu
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
/*
Small data test pass
*/
typedef long long llong;
/*
f[i][n] = f[i-1][n-1]*C(n,1) + f[i-1][n02]*C(n,2) + ... + f[i-1][i-1] * C(n, n-(i-1));
*/
#include <iostream>
#include <vector>
using namespace std;
int base = 1000000007;
typedef long long llong;
@sturgle
sturgle / exmap.cpp
Created October 13, 2014 04:05
enhanced map with random
#include <vector>
#include <map>
#include <utility>
#include <iostream>
using namespace std;
class ExMap {
map<int, int> _map; // key to index of _keyVals
vector<pair<int,int>> _keyVals;