摘要: Givennpairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, givenn= 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()"典型的递归。一步步构造字符串。当左括号出现次数 generateParenthesis(int n) { 3 // S 阅读全文
posted @ 2013-07-14 15:16 feiling 阅读(201) 评论(0) 推荐(0) 编辑
摘要: Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct order,"()"and"()[]{}"are all valid but"(]"and"([)]"are not.思路: 阅读全文
posted @ 2013-07-14 13:57 feiling 阅读(191) 评论(0) 推荐(0) 编辑
摘要: Given a linked list, remove thenthnode from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the linked list becomes 1->2->3->5.思路:两个指针,未能一次通过。。。。当需删除的元素是第一个元素时,直接按24-27进行删除 1 /** 2 * Defin 阅读全文
posted @ 2013-07-14 13:40 feiling 阅读(251) 评论(0) 推荐(0) 编辑