自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(37)
  • 收藏
  • 关注

原创 LeetCode(321)Create Maximum Number

题目:Given two arrays of length m and n with digits 0-9 representing two numbers. Create the maximum number of length k  from digits of the two. The relative order of the digits from the same

2016-12-21 00:16:51 282

原创 LeetCode(316)Remove Duplicate Letters

题目:Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographica

2016-12-21 00:16:24 356

原创 LeetCode(455)Assign Cookies

题目:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum si

2016-11-24 18:36:12 213

原创 LeetCode(135)Candy

题目:There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have at

2016-11-24 18:27:12 246

原创 LeetCode(134) Gas Station

题目:There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from statio

2016-11-24 17:54:29 206

原创 作业题8.23

2016-11-23 23:44:57 1246

原创 LeetCode(45) Jump Game II

题目: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.Yo

2016-11-06 21:40:17 234

原创 LeetCode(55)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.Determin

2016-11-06 21:08:44 162

原创 LeetCode(44) Wildcard Matching

题目:'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function prototyp

2016-11-06 18:41:11 222

原创 LeetCode(279)Perfect Squares

题目:Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4;

2016-11-01 18:35:58 151

原创 LeetCode(152) Maximum Product Subarray

题目:找最大的连乘积。Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3]

2016-10-30 23:42:31 139

原创 LeetCode(263) Ugly Number (264)Ugly Number II

263题目:ugly number是因数只包含2,3,5的数。判断一个数是不是ugly numberWrite a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3,

2016-10-30 22:21:07 245

原创 LeetCode(122) Best Time to Buy and Sell Stock II

题目:可以买卖任意多次,求利润最大值。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 as many transaction

2016-10-30 22:17:44 182

原创 LeetCode(121) Best Time to Buy and Sell Stock

题目:选定某天买入,另一天卖出。只能最多一次买和卖,求最大利润Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy

2016-10-30 22:07:39 162

原创 LeetCode(213) House Robber II

题意:和House Robber I一样,只是首尾两个数也不能同时取。After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all

2016-10-30 22:02:12 238

原创 LeetCode(198) House Robber

题意:给一组非负整数,不能同时取相邻的两个数,求它们的和的最大值。You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robb

2016-10-30 21:56:03 194

原创 LeetCode(120) Triangle

题意:计算一个三角形从上到下的路径和的最小值。Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle

2016-10-20 00:17:43 178

原创 LeetCode(95) Unique Binary Search Trees II

题意:和Unique Binary Search Trees I一样,但是要返回不同的二分搜索树。Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your prog

2016-10-20 00:08:06 171

原创 Leetcode(64)Minimum Path Sum

题目:从左上到右下,只能向右和向下走,求经过的数字和的最小值。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

2016-10-17 22:01:26 176

原创 LeetCode(96) Unique Binary Search Trees

题目:给定n个结点1...n,能够成多少种不同的二分查找树Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1

2016-10-14 10:08:36 180 1

原创 LeetCode(70) Climbing Stairs

题目:爬梯,每次爬一步或者两步,爬上n层一共有多少种方法。解法:实在太简单了,考虑最后一次迈步,可以迈一步或者两步,两种方式不重合,所以f(n)=f(n-1)+f(n-2)。复杂度O(n)。代码:class Solution {public: int climbStairs(int n) { int a=0,b=1,c;//c=a+b; for

2016-10-14 00:20:14 136

原创 Leetcode(91) 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 digit

2016-10-14 00:12:42 116

原创 LeetCode(63) Unique Paths II

题目:和 Unique Paths一样,只是设了路障。Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked

2016-10-13 23:51:26 258

原创 Leetcode(62)Unique Paths

题目:从左上角到右下角,只能往右走或者往下走,有多少种不同的走法。A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in

2016-10-13 23:13:22 154

原创 Leetcode(10)Regular Expression Matching

题目:字符串匹配。‘.’可以匹配任意字符,‘*’可以匹配任意多个相同的字符。‘.’ Matches any single character.‘*’ Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).

2016-10-13 18:36:32 166

原创 Leetcode(310) Minimum Height Trees

题目:求最小高度树For a undirected graph with tree characteristics, we can choose any node as the root. The result graph is then a rooted tree. Among all possible rooted trees, those with minimum heigh

2016-10-13 18:19:18 215

原创 Leetcode(207)Course Schedule (210)Course Schedule II

题目:207 Course Schedule 课程之间有先修和后修的关系限制,判断是否能修完所有课程。即判断有向图是否有环。210 Course Schedule II 课程之间有先修和后修的关系限制,给出一种满足限制的顺序,不存在的返回空vector。即给出有向图的拓扑排序。解法:拓扑排序。代码:class Solution {public: vector

2016-10-13 15:23:36 183

原创 LeetCode(133) Clone Graph

题目:复制一张无向图.Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a s

2016-10-13 15:12:13 162

原创 LeetCode(241)Different Ways to Add Parentheses

题意:代码:class Solution {public: vector diffWaysToCompute(string input) { vector result; for(int i=0;i<input.size();i ++) { if(input[i]=='+'||inp

2016-09-25 22:15:35 343 1

原创 LeetCode(240)Search a 2D Matrix II

题意:在一个m*n的二维矩阵中查找一个目标值。矩阵每一行从左到右升序排列,每一列从上到下升序排列。例如:[ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19], [3, 6, 9, 16, 22], [10, 13, 14, 17, 24], [18, 21, 23, 26, 30]]分析:二维矩阵的右上角元素有特殊性:

2016-09-25 21:26:24 293

原创 leetcode(169)Majority Element

题意:找出数组中的主元素(出现次数超过[n/2]的元素)分析:这道题比较有意思,解法很多而且很巧妙,搜集了一些网上介绍的方法,时间复杂度都是O(n)。1、成对删除。不断把两个不同元素删除,因为主元素次数超过[n/2],所以最后一定剩下至少一个元素,剩下的这些元素就是主元素。2、随机数法。随机选择一个元素,判断它出现的次数是否超过[n/2]。因为主元素的个数超过n/2,所以理论上平均每取

2016-09-23 21:53:08 192

原创 leetcode(53)Maximum Subarray

题意:找到最大子数组的和。分析:用分治法。假设把一个数组[low,high]分成两半[low,mid]和[mid,high],那么[low,high]的最大子序列之和只可能是以下三者中的最大值:           1、[low,mid]的最大子序列之和。           2、[mid+1,high]的最大子序列之和。           3、一个横跨[low,mid]和[mi

2016-09-23 21:12:24 147

原创 LeetCode(23)Merge k Sorted Lists

题意:合并k个有序链表方法:类似归并排序分析:      用归并排序的做法,将k个有序链表先两两排序,变成k/2个链表,然后这k/2个链表再两两排序,变成k/4个链表,以此类推,直到最后只有1个链表。     例如有8个链表。     第一次:将第0个和第4个合并为第0个链表、将第1个和第5个合并为第1个链表、将第2个和第6个合并为第2个链表、将第3个和第7个合并为第3个链表。

2016-09-18 19:39:50 247

原创 LeetCode(4)Median of Two Sorted Arrays

题意:给定两个已排序的数组,找出合起来的中位数。难度:hard思路:参考https://discuss.leetcode.com/topic/4996/share-my-o-log-min-m-n-solution-with-explanation将中位数理解为把一个集合分成两个长度相等(或相差1)的子集,并且一个子集的所有元素都不大于另一个子集。现在要做的是把A、B数组划分成

2016-09-05 23:18:54 219

原创 LeetCode(3)Longest Substring Without Repeating Characters

题意:找出字符串的没有重复字母的最长子串。难度:中等思路:最简单的是O(n²)的枚举:从1~n枚举Si,对于每个Si,找到最长的没有重复字母的子串。这种做法效率很低。           另一种做法是:用两个变量i和j表示没有重复字母的子串的两端。如果S[j+1]没有在(Si,Si+1,...,Sj)中出现过,则j加1,相当于扩展了字符串。如果S[j+1]在(Si,Si+1,...,S

2016-09-04 21:38:06 213 1

原创 LeetCode(2) Add Two Numbers

题意:用两个list表示两个非负整数,求它们的和思路:从最低位起,对应位的两个数字相加,再加上上一位的进位。代码:class Solution {public:    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {        int t=l1->val+l2->val;        ListNode* s

2016-09-04 19:37:21 176

原创 LeetCode第一题

题意:在一组整数中找到两个数的,使它们的和等于给定的一个整数。

2016-09-04 18:17:54 445 1

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除