Skip to content

Instantly share code, notes, and snippets.

@junjiah
junjiah / fn_extract_cause.py
Last active December 22, 2015 23:49
extract causation frame's Cause and Effect role from FrameNet annotated corpus
from lxml import etree as ET
from itertools import chain
import sys
if len(sys.argv) > 1:
f = open(sys.argv[1])
else:
f = open('x.xml') # default xml file
# first, remove namespace
import java.util.HashMap;
import java.util.Map;
/**
* Created with IntelliJ IDEA.
* User: EDFward
* Date: 11/17/13
* Time: 12:52 AM
* Happy coding!
*/
@junjiah
junjiah / 0_reuse_code.js
Created November 17, 2013 04:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
/*
1. first using DP, O(n^2), TLE.
2. then try spliting arrays to intervals by
taking the maximum reach as the boundary.
*/
class Solution {
public:
int jump(int A[], int n) {
if (A[0] == 0 || n == 1) return 0;
int iter = 1, intervalEnd = A[0], res = 1;
@junjiah
junjiah / interleaving_string.cpp
Last active December 29, 2015 08:08
solved 'Interleaving String' on LeetCode (6 submissions, fxxk!) http://oj.leetcode.com/problems/interleaving-string/
/*
1. first tried backtracking, TLE
2. 2-dimension DP, accepted. state transition is easy to derive
*/
class Solution {
public:
bool isInterleave(string s1, string s2, string s3) {
m = s1.size();
n = s2.size();
if (s3.size() != m+n) return 0;
@junjiah
junjiah / ReorderList.java
Last active December 29, 2015 13:39
solved 'Reorder List' on LeetCode (ONE AC! oh yeah;) http://oj.leetcode.com/problems/reorder-list/
/**
* Definition for singly-linked list.
* class ListNode {
* int val;
* ListNode next;
* ListNode(int x) {
* val = x;
* next = null;
* }
* }
"""
(C) Mathieu Blondel - 2010
License: BSD 3 clause
Implementation of the collapsed Gibbs sampler for
Latent Dirichlet Allocation, as described in
Finding scientifc topics (Griffiths and Steyvers)
"""
@junjiah
junjiah / WaterContainer.java
Last active December 30, 2015 17:19
solved 'Container With Most Water ' on LeetCode (ONE AC lol) http://oj.leetcode.com/problems/container-with-most-water/ [better O(n) algorithm is also attached - from Web]
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Created with IntelliJ IDEA.
* User: EDFward
* Date: 12/8/13
* Time: 9:56 PM
@junjiah
junjiah / MaxPoints.java
Last active January 1, 2016 03:19
solved 'Max Points on a Line' on LeetCode (TRICK: use strings to represent lines!) http://oj.leetcode.com/problems/max-points-on-a-line/
/*
reduced code from 120 lines to 40 lines:
no need to build classes like Line and Fraction!
it's enough to
1. represent lines using only slope since point i
is fixed
2. use string as the key of hashmap
*/
public class Solution {