关闭

Best Time to Buy and Sell Stock III - LeetCode 123

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. Note: You may not ...
阅读(428) 评论(0)

Perfect Squares - LeetCode 279

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; given n =...
阅读(216) 评论(0)

Missing Number - LetcCode 268

Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example, Given nums = [0, 1, 3] return 2. Note: Your algorithm should ru...
阅读(228) 评论(0)

Product of Array Except Self - LeetCode 238

Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. Solve it without division and in O(n...
阅读(176) 评论(0)

Gas Station - LeetCode 134

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 station i to it...
阅读(188) 评论(0)

3Sum Closest - LeetCode 16

题目描述: 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 hav...
阅读(212) 评论(0)

Summary Ranges - LeetCode 228

题目描述: Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. Credits: Special thanks to @jianchao.li.fight...
阅读(247) 评论(0)

Search in Rotated Sorted Array - LeetCode 33

题目描述: 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 in the array re...
阅读(261) 评论(0)

Basic Calculator II - LeetCode 227

题目描述: Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division sho...
阅读(301) 评论(0)

Jump Game - LeetCode 55

题目描述: 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...
阅读(232) 评论(0)

First Missing Positive - LeetCode 41

题目描述: 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 uses c...
阅读(202) 评论(0)

Median of Two Sorted Arrays - LeetCode 4

题目描述: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Tags: Divide and Con...
阅读(220) 评论(0)

Path Sum II - LeetCode 113

题目描述: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. For example: Given the below binary tree and sum = 22,               5              ...
阅读(187) 评论(0)

Sqrt(x) - LeetCode 69

题目描述: Implement int sqrt(int x). Compute and return the square root of x. Hide Tags Math Binary Search 分析:类型都是整型,直接二分 但是要注意处理非完全平方数。 /**///////////////////////8ms//*/ class Solution { public: ...
阅读(174) 评论(0)

Search for a Range - LeetCode 34

题目描述: 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 target is not fou...
阅读(247) 评论(0)

Flatten Binary Tree to Linked List - LeetCode 114

题目描述: Given a binary tree, flatten it to a linked list in-place. For example, Given          1         / \        2   5       / \   \      3   4   6 The flattened tree should look like:   ...
阅读(184) 评论(0)

Sum Root to Leaf Numbers - LeetCode 129

题目描述: Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the tot...
阅读(258) 评论(0)

Sort List - LeetCode 148

题目描述 : Sort a linked list in O(n log n) time using constant space complexity. Hide Tags Linked List Sort 分析: 上一题是用插入排序,时间复杂度是O(N^2),这一题要求的时间复杂度只能是快排,归并,或堆。对于数组来讲,这三个算法都是比较容易实现,但是对于链表,快排不太适合,因为每次只将...
阅读(228) 评论(0)

Insertion Sort List - LeetCode 147

题目描述: Sort a linked list using insertion sort. Hide Tags Linked List Sort 分析: 插入排序是在一个已排序的序列中找到当前元素正确的位置,然后插入禁区即可。 由于链表不能随机访问,所以每处理一个元素时,都必须从前往后找到正确的位置,然后插入节点即可。 为了方便操作,可以新建一个带有头节点的链表new...
阅读(209) 评论(0)

Bitwise AND of Numbers Range - LeetCode 201

题目描述: Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4. Credits: Special thanks to @amrsaqr for adding this problem and creating all test cases. Hide Tag...
阅读(236) 评论(0)
99条 共5页1 2 3 4 5 ... 下一页 尾页
    个人资料
    • 访问:28403次
    • 积分:1212
    • 等级:
    • 排名:千里之外
    • 原创:97篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条
    文章分类