Skip to content

Instantly share code, notes, and snippets.

View charlespunk's full-sized avatar

charlespunk charlespunk

View GitHub Profile
public class Solution {
public boolean canFinish(int numCourses, int[][] prerequisites) {
Course[] courses = new Course[numCourses];
for (int i = 0; i < courses.length; i ++) {
courses[i] = new Course();
}
for (int[] edge : prerequisites) {
Course in = courses[edge[0]];
Course out = courses[edge[1]];
if (!out.outNeighbours.contains(in)) {
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public class Solution {
public List<Integer> spiralOrder(int[][] matrix) {
List<Integer> out = new ArrayList<>();
if (matrix.length == 0) {
return out;
}
int firstRow = 0;
int lastRow = matrix.length - 1;
int firstColumn = 0;
int lastColumn = matrix[0].length - 1;
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public class Solution {
class State {
boolean end;
Map<Character, List<State>> transferTable;
State() {
transferTable = new HashMap<>();
}
void addTransfer(char c, State next) {
if (transferTable.containsKey(c)) {
public class WordDictionary {
private TrieNode root;
public WordDictionary() {
this.root = new TrieNode();
}
// Adds a word into the data structure.
public void addWord(String word) {
TrieNode currentNode = root;
class TrieNode {
// Initialize your data structure here.
private Map<Character, TrieNode> children;
private boolean isWord;
public TrieNode() {
this.children = new HashMap<>();
}
TrieNode addLetter(Character letter) {
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by benjamin on 10/21/14.
*/
public class PalindromePartitioningII {
public int minCut(String s) {
if (s.length() <= 1) {
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Created by benjamin on 10/20/14.
*/
public class PalindromePartitioning {
public List<List<String>> partition(String s) {
boolean[][] dp = new boolean[s.length()][s.length()];