![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 69
gaowei199120
这个作者很懒,什么都没留下…
展开
-
leetcode Best Time to Buy and Sell Stock
题目的意思是整个过程中只能买一只股票然后卖出,也可以不买股票。也就是我们要找到一对最低价和最高价,最低价在最高价前面,以最低价买入股票,以最低价卖出股piao原创 2014-05-04 14:39:54 · 602 阅读 · 0 评论 -
leetcode Palindrome Partitioning II
题目:Given a string s, partition s such that every substring of the partition is a palindrome.Return the minimum cuts needed for a palindrome partitioning of s.For example, given s = "aab"原创 2014-05-08 10:21:39 · 551 阅读 · 0 评论 -
leetcode Longest Valid Parentheses
思路://引入一个bool数组flag[], flag[i]标记i位置能不能匹配 //最后统计最长true的长度class Solution {public: //引入一个bool数组flag[], flag[i]标记i位置能不能匹配 //最后统计最长true的长度 int longestValidParentheses(string s) {原创 2014-05-08 16:46:16 · 463 阅读 · 0 评论 -
leetcode First Missing Positive
思路:虽然不能再另外开辟非常数级的额外空间,但是可以在输入数组上就地进行swap操作。思路:交换数组元素,使得数组中第i位存放数值(i+1)。最后遍历数组,寻找第一个不符合此要求的元素,返回其下标。整个过程需要遍历两次数组,复杂度为O(n)。下图以题目中给出的第二个例子为例,讲解操作过程。int firstMissingPosit转载 2014-05-08 11:07:20 · 485 阅读 · 0 评论 -
leetcode Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","原创 2014-05-07 17:06:48 · 482 阅读 · 0 评论 -
leetcode Decode Ways
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 nu原创 2014-05-07 14:05:53 · 453 阅读 · 0 评论 -
leetcode Edit Distance
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2014-05-06 15:23:08 · 437 阅读 · 0 评论 -
leetcode Restore IP Addresses
题目 :Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Or原创 2014-05-06 17:02:46 · 483 阅读 · 0 评论 -
leetcode Jump Game
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 position.Determine i原创 2014-05-05 20:04:23 · 526 阅读 · 0 评论 -
leetcode Word Break
分析:题目意思是,给定词典的情况下,看看原字符串能不能全部成功地被给定的词典分割。思路:原创 2014-05-05 10:41:24 · 481 阅读 · 0 评论 -
leetcode Max Points on a Line
文章摘自:http://blog.csdn.net/doc_sgl/article/details/17103427分析:任意一条直线都可以表述为y = ax + b假设,有两个点(x1,y1), (x2,y2),如果他们都在这条直线上则有y1 = kx1 +by2 = kx2 +b由此可以得到关系,k = (y2-y1)/(x2转载 2014-05-04 19:54:37 · 435 阅读 · 0 评论 -
leetcode Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete at most two transactions.原创 2014-05-04 16:03:37 · 588 阅读 · 0 评论 -
leetcode Best Time to Buy and Sell Stock II
分析:题目的意思是整个过程中只能买一只股票然后卖出,也可以不买股票。也就是我们要找到一对最低价和最高价,最低价在最高价前面,以最低价买入股票,以最低价卖出股票。可以买卖多次股票,但是不能连续买股票,也就是说手上最多只能有一只股票(注意:可以在同一天卖出手上的股票然后再买进)原创 2014-05-04 15:13:15 · 758 阅读 · 0 评论 -
leetcode Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2014-05-12 09:46:35 · 490 阅读 · 0 评论