Skip to content

Instantly share code, notes, and snippets.

View tolinwei's full-sized avatar

Wei Lin tolinwei

  • Facebook
  • Cambridge, MA
View GitHub Profile
/**
* Created by linwei on 9/20/16.
*/
class IsSubstring {
public boolean isSubstring(String source, String pattern) {
if (source == null || pattern == null) {
return false;
}
for (int i = 0; i < source.length(); i++) {
import javax.naming.OperationNotSupportedException;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Created by linwei on 9/20/16.
*/
import javax.naming.OperationNotSupportedException;
import java.util.ArrayList;
import java.util.Iterator;
@tolinwei
tolinwei / MyList.java
Last active September 20, 2016 21:34
import javax.naming.OperationNotSupportedException;
import java.util.ArrayList;
import java.util.Iterator;
/**
* Created by linwei on 9/20/16.
*/
public class MyList extends ArrayList<Character> {
@Override
public Iterator<Character> iterator() {
@tolinwei
tolinwei / maxAmp.cpp
Created September 18, 2016 01:07 — forked from joe-cai/maxAmp.cpp
Maximal Amplitude of a Binary Tree
class TreeNode {
int val;
TreeNode* left;
TreeNode* right;
TreeNode(int val_) : val(val_) {}
};
class Solution {
int ans = 0;
int maxAmp(struct TreeNode* root) {
@tolinwei
tolinwei / LockTest.java
Created May 13, 2016 01:21
Java ReentrantLock and Condition Variables
import java.util.concurrent.*;
import java.util.concurrent.locks.*;
import java.io.IOException;
/**
* Created by jianye on 5/12/16.
* Modified by Wei on 5/13/16.
*/
import java.util.concurrent.*;
import java.util.concurrent.locks.*;
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void dfs(string &num, int offset, vector<string> &map, string &solution, vector<string> &result)
{
if (solution.size() == num.size()) {
//cout << "n" << endl;
result.push_back(solution);
return;
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct comparator
{
bool operator() (int a, int b) {
return a > b;
}
};
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
inline bool comparator(const int &a, const int &b)
{
return a < b;
}
int maintain(vector<int> &v)
{
/* six degree separation */
struct GraphNode
{
string name; //name of actors
bool visited; //visited
vector<GraphNode *> neighbors; //neighbor nodes
GraphNode(string n) : name(n), visited(false) {}
};
/* find the path */
void bfs_helper(GraphNode *end, queue<vector<GraphNode *>> q, bool &found, vector<GraphNode *> &ret)
/* just show rough idea, can't be compiled */
/* reference */
/* http://m.oschina.net/blog/57529 */
struct Co
{
float x_co;
float y_co;
Co(float x, float y) : x_co(x), y_co(y) {}
};