上一页 1 2 3 4 5 6 7 8 9 ··· 20 下一页
摘要: Problem Description:Givennnodes labeled from0ton - 1and a list of undirected edges (each edge is a pair of nodes), write a function to check whether t... 阅读全文
posted @ 2015-08-18 10:58 jianchao-li 阅读(3458) 评论(0) 推荐(1) 编辑
摘要: A typical DFS problem. Just go ahead... 1 class Solution { 2 public: 3 bool exist(vector>& board, string word) { 4 int m = board.size(), n... 阅读全文
posted @ 2015-08-18 00:11 jianchao-li 阅读(212) 评论(0) 推荐(0) 编辑
摘要: A simple combination of Implement Trie (Prefix Tree) and Word Search. If you've solved them, this problem will become easy :-)The following code is ba... 阅读全文
posted @ 2015-08-17 22:49 jianchao-li 阅读(362) 评论(0) 推荐(0) 编辑
摘要: You need to understand what a Trie is before writing the code :-) This link has a nice solution, whose code is rewritten below. 1 class TrieNode { 2 p... 阅读全文
posted @ 2015-08-17 21:24 jianchao-li 阅读(233) 评论(0) 推荐(0) 编辑
摘要: This problem is purely to test your coding ability. Just go ahead :-) 1 class Solution { 2 public: 3 string countAndSay(int n) { 4 string ... 阅读全文
posted @ 2015-08-17 17:06 jianchao-li 阅读(183) 评论(0) 推荐(0) 编辑
摘要: Try to split all the numbers into two groups with each of the target one in different groups. Refer to this link for a nice explanation.The code is wr... 阅读全文
posted @ 2015-08-17 16:16 jianchao-li 阅读(190) 评论(0) 推荐(0) 编辑
摘要: Problem Description:Given an array ofnintegersnumsand atarget, find the number of index tripletsi, j, kwith0 & nums, int target) { 4 sort(nums... 阅读全文
posted @ 2015-08-17 15:50 jianchao-li 阅读(5070) 评论(0) 推荐(0) 编辑
摘要: Well, no matter whether the number is happy or not, its sum-of-squared-digits sequance has a cycle. Well, do you still remember the algorithm for dete... 阅读全文
posted @ 2015-08-17 00:12 jianchao-li 阅读(177) 评论(0) 推荐(0) 编辑
摘要: Dynamic ProgrammingThere is a nice introduction to the DP algorithm in thisWikipedia article. The idea is to maintain a running maximumsmaxand a curre... 阅读全文
posted @ 2015-08-16 15:55 jianchao-li 阅读(318) 评论(0) 推荐(0) 编辑
摘要: Well, if you have no idea of other methods, try to compue the result for all the numbers ranging from 1 to 20 and then you will see the regularity. Af... 阅读全文
posted @ 2015-08-16 13:36 jianchao-li 阅读(225) 评论(0) 推荐(0) 编辑
摘要: The basic idea is to start fromrootand add it to the currentpath, then we recursively visit itsleftandrightsubtrees if they exist; otherwise, we have ... 阅读全文
posted @ 2015-08-16 10:48 jianchao-li 阅读(336) 评论(0) 推荐(0) 编辑
摘要: The idea is to add the two binary numbers (represented as strings) from back to forth bit by bit and store the result in the longer string. After the ... 阅读全文
posted @ 2015-08-16 00:36 jianchao-li 阅读(198) 评论(0) 推荐(0) 编辑
摘要: This problem is just similar toMinimum Depth of Binary Tree.The first solution also uses recursion (not sure whether it can be called DFS).1 class Sol... 阅读全文
posted @ 2015-08-15 18:43 jianchao-li 阅读(182) 评论(0) 推荐(0) 编辑
摘要: Well, this problem has the highest acceptance rate among all OJ problems. It has a very easy 1-line reursive solution. I am not sure whether this one ... 阅读全文
posted @ 2015-08-15 18:23 jianchao-li 阅读(172) 评论(0) 推荐(0) 编辑
摘要: The basic idea is to use binary search: keep two pointerslandrfor the current search range, then find the middle elementnums[mid]in this range. Ifnums... 阅读全文
posted @ 2015-08-15 17:41 jianchao-li 阅读(172) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 20 下一页