Tag Archives: DFS

Number of Distinct Islands
Leave a commentOctober 8, 2017 by oneOokay
问题在于如何存/translate an island so you can distinct them from each other. 我的代码跑过了所有700+个test case但是就是最后两个跑不过,而且test case太大不可能debug.最终拿了别人的pass的代码一个一个比较output才明白为什么我卡在最后两个test case了… 我的: main method里面 boolean[][] visited和String …
Continue reading 
Walls and Gates
Leave a commentSeptember 21, 2017 by oneOokay
You are given a m x n 2D grid initialized with these three possible values. 1 – A wall or an obstacle. 0 – …
Continue reading 
01 Matrix
Leave a commentJune 20, 2017 by oneOokay
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance …
Continue reading 
Generate Parentheses
Leave a commentMay 14, 2017 by oneOokay
Given n pairs of parentheses, write a function to generate all combinations of wellformed parentheses. For example, given n = …
Continue reading 
Word Squares / Word Search II
Leave a commentJanuary 16, 2017 by oneOokay
TODO: Word SearchII Word Squares 需要一个数据结构来很快的找到以某个prefix开始的string是否存在于dictionary中 Trie是高级的写法 低级一点的可以直接用hash同来算:Hash<String,List>key为prefix, list为以这个prefix开始的string… 理清思路: 首先建一个trie, trie的结构是怎么样的呢?先想到这样.因为需要到一个节点的时候知道以这个节点位置为prefix的所有的string都有哪些,所以在每个节点上都要存word TrieNode[] next List words 在主函数里面需要forloop吗?还是直接在dfs helper method里面? 放第一个,放中间一个和放最后一个word的logic是一模一样的,所以应该都放在dfs里面. …
Continue reading 
Longest Increasing Path in a Matrix
Leave a commentDecember 19, 2016 by oneOokay
Given an integer matrix, find the length of the longest increasing path. From each cell, you can either move to …
Continue reading 
Topological Sorting Related
Leave a commentDecember 18, 2016 by oneOokay
拓扑排序以及相关题目： 拓扑排序 For each directed edge A > B in graph, A must before B in the order list. The …
Continue reading