摘要: 简单题。DFS。还是用Java写函数麻烦了。一开始把left<n的条件忘了。 import java.util.ArrayList; public class Solution { public ArrayList<String> generateParenthesis(int n) { // St 阅读全文
posted @ 2013-07-29 22:59 阿牧遥 阅读(195) 评论(0) 推荐(0)
摘要: 简单题。使用stack就行了。不过一开始忘了判断'['和']'的情况。要判断stack是否为空。 #include <string> #include <stack> using namespace std; class Solution { public: bool isValid(string 阅读全文
posted @ 2013-07-29 22:01 阿牧遥 阅读(166) 评论(0) 推荐(0)
摘要: 简单题。唯一的小技巧是使用了指向指针的指针。 class Solution { public: ListNode *removeNthFromEnd(ListNode *head, int n) { // Start typing your C/C++ solution below // DO NO 阅读全文
posted @ 2013-07-29 21:48 阿牧遥 阅读(159) 评论(0) 推荐(0)
摘要: DFS,用C会更合适一些,用Java就要传很多的引用。在我看来,这个DFS就是递归。import java.util.ArrayList;import java.util.HashMap;public class Solution { public ArrayList letterCombin... 阅读全文
posted @ 2013-07-29 17:26 阿牧遥 阅读(568) 评论(0) 推荐(0)
摘要: 此题是Two Sum的变种,Two Sum能从O(n^2)优化到O(n)。那么此题能从O(n^3)优化到O(n^2)。就是少了那一维n。此处要注意:1.当有重复的数字时,要跳过;2.找好一个数字去寻找另外两个数字时,只需从右边部分寻找就行,否则会重复。import java.util.ArrayLi... 阅读全文
posted @ 2013-07-29 16:36 阿牧遥 阅读(231) 评论(0) 推荐(0)
摘要: 水题。一个一个字符串比较就是了。public class Solution { public String longestCommonPrefix(String[] strs) { // Start typing your Java solution below // DO NOT write main() function if (strs == null || strs.length == 0) return ""; String s = strs[0]; for (int i = 1; i < strs.length; i+... 阅读全文
posted @ 2013-07-29 15:34 阿牧遥 阅读(207) 评论(0) 推荐(0)