This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given a 2D board and a word, find if the word exists in the grid. | |
The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once. | |
For example, | |
Given board = | |
[ | |
["ABCE"], | |
["SFCS"], |
NewerOlder