2014年4月11日

【LeetCode练习题】Unique Paths

摘要: Unique PathsA robot is located at the top-left corner of amxngrid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).How many 阅读全文

posted @ 2014-04-11 19:54 Allen Blue 阅读(213) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Longest Valid Parentheses

摘要: Longest Valid ParenthesesGiven a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substring.For"(()", the longest valid parentheses substring is"()", which has length = 2.Another example is")()())& 阅读全文

posted @ 2014-04-11 16:27 Allen Blue 阅读(208) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Scramble String

摘要: Scramble StringGiven a strings1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation ofs1="great": great / \ gr eat / \ / \g r e at / \ a tTo scramble the string, we may choose ... 阅读全文

posted @ 2014-04-11 11:43 Allen Blue 阅读(217) 评论(0) 推荐(0) 编辑

2014年4月9日

【LeetCode练习题】Linked List Cycle II

摘要: Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?Linked List Cycle IIGiven a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?题目意思:第一个 阅读全文

posted @ 2014-04-09 21:01 Allen Blue 阅读(236) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Permutation Sequence

摘要: Permutation SequenceThe set[1,2,3,…,n]contains a total ofn! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, forn= 3):"123""132""213""231""312""321"Givennandk, return thekthperm 阅读全文

posted @ 2014-04-09 19:41 Allen Blue 阅读(148) 评论(0) 推荐(0) 编辑

2014年4月8日

求连续子数组的最大和

摘要: 题目来源:《剑指offer》面试题31,《编程珠玑》第八章,LeetCode OJ的Maximum Subarray。题目大意:输入一个整型数组,数组里有正数也有负数。数组中一个或连续的多个整数组成一个子数组。求所有子数组的最大和。例如,数组为{1,-2,3,10,-4,7,2,-5},和最大的子数组为{3,10,-4,7,2},因此返回的结果为子数组的和18.来自Google,微软等很多知名公司的面试题,2005年浙江大学计算机系的考研题的最后一道程序设计题,貌似是风靡一时的一道题。参考链接:程序员编程艺术:第七章、求连续子数组的最大和、程序员面试题精选100题(03)-子数组的最大和解题思 阅读全文

posted @ 2014-04-08 23:19 Allen Blue 阅读(211) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Gas Station

摘要: Gas StationThere areNgas stations along a circular route, where the amount of gas at stationiisgas[i].You have a car with an unlimited gas tank and it costscost[i]of gas to travel from stationito its next station (i+1). You begin the journey with an empty tank at one of the gas stations.Return the s 阅读全文

posted @ 2014-04-08 18:16 Allen Blue 阅读(136) 评论(0) 推荐(0) 编辑

再来看看快速排序

摘要: #include #include #include using namespace std;void quickSort(vector &vec,int l,int u){ int i , m; if( l>=u) return ; m = l; for(i = l+1; i vec){ vector::iterator it = vec.begin(); for(; it != vec.end(); it++) cout vec; for(int i = 1; i = u) return; 4 m = l; 5 f... 阅读全文

posted @ 2014-04-08 13:52 Allen Blue 阅读(265) 评论(0) 推荐(0) 编辑

【LeetCode练习题】First Missing Positive

摘要: First Missing PositiveGiven an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should run inO(n) time and uses constant space.题目意思:返回第一个缺失的正数。时间复杂度应该在O(n)且只能使用常数的额外空间。解题思路:遍历两遍数组,第一遍的目的是使数组下标为 i 的数值设置为 i+1,如没有 i+1 就是 阅读全文

posted @ 2014-04-08 00:07 Allen Blue 阅读(136) 评论(0) 推荐(0) 编辑

2014年4月7日

【LeetCode练习题】Merge Sorted Array

摘要: Merge Sorted ArrayGiven two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal tom+n) to hold additional elements from B. The number of elements initialized in A and B aremandnrespectively.题目意思:将两个有序的数组合并成一个有序的 阅读全文

posted @ 2014-04-07 23:37 Allen Blue 阅读(161) 评论(0) 推荐(0) 编辑

导航