- 博客(47)
- 资源 (2)
- 收藏
- 关注
原创 leetcode || 53、Maximum Subarray
problem:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous su
2015-03-31 17:44:05 558
原创 leetcode || 50、Pow(x, n)
problem:Implement pow(x, n).Hide Tags Math Binary Search题意:求x的n次幂thinking:(1)最简单想到的是直观上的数学幂函数求法,测试通过。算法时间复杂度为O(n)(2)按照标签提示,使用二分搜索法。pow(x,n) = po
2015-03-31 09:15:00 738
原创 leetcode || 49、Anagrams
problem:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.Hide Tags Hash Table String题意:给定多余两组的字符串,找出其中所有的满足以下条
2015-03-30 17:19:09 682
原创 leetcode || 48、Rotate Image
problem:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?Hide Tags Array题意:将一个矩阵顺时针旋
2015-03-30 16:44:29 691
原创 leetcode || 47、 Permutations II
problem:Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1],
2015-03-30 16:17:55 639
原创 leetcode || 46、Permutations
problem:Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,
2015-03-30 15:32:01 698
原创 leetcode || 45、 Jump Game II
problem:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that posi
2015-03-30 10:49:25 634
原创 leetcode || 43、Multiply Strings
problem:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.Hide Tags Math
2015-03-27 16:07:14 876
原创 leetcode || 42、 Trapping Rain Water
problem:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [
2015-03-27 10:46:28 1187
原创 leetcode || 41、First Missing Positive 问题
problem:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and
2015-03-26 20:00:09 623
原创 leetcode || 40、Combination Sum II
problem:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used
2015-03-26 16:45:03 427
原创 leetcode || 39、Combination Sum
problem:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen f
2015-03-26 15:34:08 708
原创 leetcode 题解 || Count and Say 问题
problem:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.
2015-03-25 17:28:06 1031
原创 leetcode 题解 || Valid Sudoku 问题
problem:Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A
2015-03-25 15:13:12 1244
原创 leetcode 题解 || Search Insert Position 问题
problem:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no dupl
2015-03-25 10:42:02 617
原创 leetcode 题解 || Search for a Range 问题
problem:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the ta
2015-03-25 09:52:00 725
原创 leetcode 题解 || Search in Rotated Sorted Array 问题
problem:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found
2015-03-25 09:04:34 718
原创 leetcode 题解 || Next Permutation 问题
problem:Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as t
2015-03-24 15:13:07 1037
原创 leetcode 题解 || Implement strStr() 问题 (即 KMP 算法实现)
problem:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Update (2014-11-02):The signature of the functio
2015-03-24 11:03:37 1328
转载 KMP字符串模式匹配详解
感谢原作者的努力:http://blog.csdn.net/a_b_c_abc/article/details/536925KMP字符串模式匹配通俗点说就是一种在一个字符串中定位另一个串的高效算法。简单匹配算法的时间复杂度为O(m*n);KMP匹配算法。可以证明它的时间复杂度为O(m+n).。一. 简单匹配算法先来看一个简单匹配算法的函数:int Index_BF ( char
2015-03-24 09:26:48 936
原创 leetcode 题解 || Remove Element 问题
problem:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond
2015-03-24 09:03:03 612
原创 leetcode 题解 || Remove Duplicates from Sorted Array 问题
problem:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in pl
2015-03-23 10:56:05 620
原创 leetcode 题解 || Swap Nodes in Pairs 问题
problem:Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant spa
2015-03-20 17:51:06 849
原创 leecode 题解 || Merge k Sorted Lists 问题
problem:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Tags Divide and Conquer Linked List Heap合并K个已序单链表thinking: (1)题目没有要求不可以新开ListN
2015-03-20 15:44:05 846
原创 高效实现 std::string split() API
Qt下 QString 实现了split()函数,而std::string则没有实现,STL中也没有实现,只能自己写一个了。#include #include using namespace std; vector split(string strtem,char a) { vector strvec; string::size_type po
2015-03-20 14:07:52 10236 1
转载 深度优先算法、广度优先算法 与 图的遍历
/***********************************/深度优先算法/***********************************/和树的遍历相似,若从图中某顶点出发访遍图中每个顶点,且每个顶点仅访问一次,此过程称为图的遍历(Traversing Graph)。图的遍历算法是求解图的连通性问题、拓扑排序和求关键路径等算法的基础。图的遍历顺序有两种:深度优先搜
2015-03-20 09:31:43 2811
原创 leetcode 题解 || Merge Two Sorted Lists 问题
problem:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.将两个已序链表合并,新链表需要拆分组合原来链表的结点,言外之意,不需要新建结点。
2015-03-19 21:48:31 515
原创 leetcode 题解 || Valid Parentheses 问题
problem: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
2015-03-19 20:34:56 758
原创 leetcode 题解 || Remove Nth Node From End of List 问题
problem:Given a linked list, remove the nth node 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
2015-03-19 19:01:48 879
原创 求和问题总结(leetcode 2Sum, 3Sum, 4Sum, K Sum)
(一)前言做过leetcode的人都知道, 里面有2sum, 3sum(closest), 4sum等问题, 这些也是面试里面经典的问题, 考察是否能够合理利用排序这个性质, 一步一步得到高效的算法. 经过总结, 本人觉得这些问题都可以使用一个通用的K sum求和问题加以概括消化, 这里我们先直接给出K Sum的问题描述和算法(递归解法), 然后将这个一般性的方法套用到具体的K, 比如leet
2015-03-19 16:35:18 2679
原创 leetcode 题解 || Letter Combinations of a Phone Number 问题
problem:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given belo
2015-03-19 11:11:24 827
原创 leetcode 题解 || 3Sum Closest 问题
problem:Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would
2015-03-19 10:05:20 650
原创 leetcode 题解 || 3Sum 问题
problem:Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b
2015-03-18 19:11:27 480
转载 C++中如何计算程序运行的时间
一个程序的功能通常有很多种方法来实现,怎么样的程序才算得上最优呢?举个例子,如果实现同一个功能的两个程序,一个一点按钮就给出运行结果,而另一个则需要漫长的时间去等待,就像安装WINDOWS XP一样(呵呵,太夸张了吧),你会去使用哪个程序呢?毋庸置疑,最优程序的第一条法则就是:程序的运行速度要快。 那么,既然一个程序能用多种方法来实现,我又如何知道哪种方法是最优的呢?有些程序是显而易见的
2015-03-18 18:34:40 690
原创 leetcode 题解 || Longest Common Prefix 问题
problem:Write a function to find the longest common prefix string amongst an array of strings.寻找 0 ~n 个字符串的最长公共前缀thinking:(1)公共前缀很好理解,按位匹配即可(2)很容易忘记处理0、1个字符串的情况。code:string prefi
2015-03-18 16:52:00 876
原创 leetcode题解 || Roman to Integer问题
problem:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.将罗马数字转为整数thinking:(1)罗马数字规则:罗马数字共有7个,即I(1)、V(5)、X(10)、L(50)、C(100)
2015-03-18 16:25:46 1061
原创 leetcode题解||Integer to Roman问题
problem:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.将1-3999的整数转换为罗马数字thinking:(1)对照举例个位数举例Ⅰ,1 】Ⅱ,2】 Ⅲ,3】 Ⅳ,4 】Ⅴ,5 】Ⅵ
2015-03-18 16:11:56 778
原创 leetcode题解||Container With Most Water问题
problem:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0)
2015-03-18 15:28:39 799
原创 leetcode题解||Regular Expression Matching 问题
problem:Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entir
2015-03-18 11:15:43 1151
转载 动态规划:从新手到专家
March 26, 2013作者:Hawstein出处:http://hawstein.com/posts/dp-novice-to-advanced.html声明:本文采用以下协议进行授权: 自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0 ,转载请注明作者及出处。前言本文翻译自TopCoder上的一篇文章: Dynami
2015-03-18 08:50:51 543
qt signal-slot测试代码
2013-12-27
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人