上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 17 下一页
摘要: Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.实现KMPclass Solution {public: char *strStr(char *haystack, char *needle) { // Start typing your C/C++ solution below // DO NOT write int main() function ... 阅读全文
posted @ 2013-09-21 23:51 懒猫欣 阅读(173) 评论(0) 推荐(0)
摘要: A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determine the total number of ways to decode it. For example,Given encoded message "12",it 阅读全文
posted @ 2013-09-21 22:57 懒猫欣 阅读(158) 评论(0) 推荐(0)
摘要: Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For example,If S = [1,2,2], a solution is:[ [2], [1], [1,2,2], [2,2], [1,2], []]普通遍历class S... 阅读全文
posted @ 2013-09-21 21:10 懒猫欣 阅读(138) 评论(0) 推荐(0)
摘要: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the following condition:1 ≤ m ≤ n ≤ length of list./** * Definition for singly-linked li 阅读全文
posted @ 2013-09-21 20:33 懒猫欣 阅读(142) 评论(0) 推荐(0)
摘要: Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any point in time.对mxn的格子扫一遍,每个格子的值等于上方和左方格子值中较小的class Solution {public: int minPathSum(vector > &am 阅读全文
posted @ 2013-09-21 19:58 懒猫欣 阅读(120) 评论(0) 推荐(0)
摘要: Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.The right subtree of a node contains only nodes with keys greater than the node's key.Both the left an 阅读全文
posted @ 2013-09-21 19:26 懒猫欣 阅读(168) 评论(0) 推荐(0)
摘要: Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?confused what "{1,#,2,3}" means? > read more on how binary tree is se 阅读全文
posted @ 2013-09-21 19:19 懒猫欣 阅读(131) 评论(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 "([)]&qu 阅读全文
posted @ 2013-09-21 16:37 懒猫欣 阅读(136) 评论(0) 推荐(0)
摘要: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()()"很简单的递归实现class Solution {public: void Sub(vector* ret,st 阅读全文
posted @ 2013-09-21 16:21 懒猫欣 阅读(183) 评论(0) 推荐(0)
摘要: Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a quadruplet (a,b,c,d) must be in non-descending order. (ie, a ≤ b ≤ c ≤ d)The solution set must not contai 阅读全文
posted @ 2013-09-20 20:31 懒猫欣 阅读(208) 评论(0) 推荐(0)
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 17 下一页