Skip to content

Instantly share code, notes, and snippets.

class Solution:
# @param s, an input string
# @param p, a pattern string
# @return a boolean
def isMatch(self, s, p):
s_len = len(s)
p_len = len(p)
dp = [[None for j in xrange(p_len + 1)] for i in xrange(2)]
# init
dp[0][0] = True
#!/bin/bash
# Script for installing tmux on systems where you don't have root access.
# tmux will be installed in $HOME/bin.
# It's assumed that wget and a C/C++ compiler are installed.
# exit on error
set -e
TMUX_VERSION=2.0
{
"template": "sfly-preprod-checksum-*",
"settings" : {
"number_of_shards" : 5,
"number_of_replicas" : 1
},
"mappings": {
"_default_": {
"_all": { "enabled": false },
"_source": { "includes": ["@signature"] },
{
"template": "sfly-preprod-logs-*",
"settings" : {
"number_of_shards" : 5,
"number_of_replicas" : 1,
"index" : {
"query" : { "default_field" : "@message" },
"store" : { "compress" : { "stored" : true, "tv": true } }
}
},
@zhoutuo
zhoutuo / jsdoc3.rb
Last active December 17, 2015 05:59 — forked from cescoffier/jsdoc3.rb
require 'formula'
class Jsdoc3 < Formula
homepage 'http://usejsdoc.org/'
url 'https://github.com/jsdoc3/jsdoc/archive/releases/3.2.zip'
def install
libexec.install Dir['*']
# Custom invoker that just passes on whatever arguments you give it
system "/bin/echo '#!/bin/sh' > jsdoc"
@zhoutuo
zhoutuo / Longest Common Prefix.cpp
Last active December 15, 2015 15:29
Write a function to find the longest common prefix string amongst an array of strings.
class Solution {
public:
string longestCommonPrefix(vector<string> &strs) {
if(strs.size() == 0) {
return "";
}
string prefix;
int index = 0;
while(true) {
@zhoutuo
zhoutuo / Largest Rectangle in Histogram.cpp
Created March 31, 2013 17:22
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3]. The largest rectangle is shown in the shaded area, which has area = 10 unit. For example, Given height = [2,1…
class Solution {
private:
vector<int> tmp;
public:
int largestRectangleArea(vector<int> &height) {
this->tmp = height;
if(height.size() == 0) {
return 0;
}
@zhoutuo
zhoutuo / Add Binary.cpp
Created March 31, 2013 07:10
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100".
class Solution {
public:
string addBinary(string a, string b) {
string c;
int lenA = a.length() - 1;
int lenB = b.length() - 1;
int left = 0;
while(lenA >= 0 or lenB >= 0 or left != 0) {
int tmpA = lenA >= 0 ? a[lenA] - '0' : 0;
int tmpB = lenB >= 0 ? b[lenB] - '0' : 0;
@zhoutuo
zhoutuo / 3Sum.cpp
Last active December 15, 2015 09:39
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ? b ? c) The solution set must not contain duplicate triplets. For example, given array S = {-1 0 1 2 -1 -4}, A sol…
class Solution {
public:
vector<vector<int> > res;
vector<int> cur;
vector<vector<int> > threeSum(vector<int> &num) {
res.clear();
cur.clear();
sort(num.begin(), num.end());
solve(num, 0, 0, 0);
return res;
@zhoutuo
zhoutuo / Distinct Subsequences.cpp
Created March 25, 2013 04:02
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, "ACE" is a subsequence of "ABCDE" while "AEC" is not)…
class Solution {
public:
int dp[100][10000];
string S;
string T;
int numDistinct(string S, string T) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
memset(dp, -1, sizeof(dp));