
leetcode
文章平均质量分 60
帘外雨
学生一枚
展开
-
Leetcode 309. Best Time to Buy and Sell Stock with Cooldown
问题描述 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 transactions as you like(ie原创 2017-07-03 21:07:44 · 177 阅读 · 0 评论 -
LeetCode:442. Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it without extra space原创 2017-09-07 16:06:20 · 228 阅读 · 0 评论 -
LeetCode:419. Battleships in a Board
Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may assume the following rules:You receive a valid board,原创 2017-09-07 15:31:18 · 221 阅读 · 0 评论 -
LeetCode:384. Shuffle an Array
Discuss Pick One <!-- @END Action Button--> <div class="question-description"> <p></p><p>Shuffle a set of numbers without dup原创 2017-09-14 21:25:01 · 395 阅读 · 0 评论 -
LeetCode: 479. Largest Palindrome Product
Find the largest palindrome made from the product of two n-digit numbers. Since the result could be very large, you should return the largest palindrome mod 1337.Example:Input: 2Output: 987Explanat原创 2017-09-06 21:49:47 · 1341 阅读 · 0 评论 -
LeetCode 382. Linked List Random Node
题目描述:LeetCode 382. Linked List Random NodeGiven a singly linked list, return a random node’s value from the linked list. Each node must have the same probability of being chosen.Follow up:What if the转载 2017-09-14 20:07:37 · 269 阅读 · 0 评论 -
LeetCode:204. Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.Credits:Special thanks to @mithmatt for adding this problem and creating all test cases. 题意:输出小于n的素数(质数)的数目。(《编程之转载 2017-09-06 18:41:20 · 202 阅读 · 0 评论 -
LeetCode: Add to List 414. Third Maximum Number
Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).Example 1:Input: [3, 2, 1]Outpu原创 2017-09-06 17:23:14 · 218 阅读 · 0 评论 -
LeetCode:529. Minesweeper
Let’s play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representing the game board. ‘M’ represents an unrevealed mine, ‘E’ represents an unrevealed empty square, ‘B’ r原创 2017-09-13 09:35:25 · 245 阅读 · 0 评论 -
LeetCode: 581. Shortest Unsorted Continuous Subarray
Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too. You need to find t原创 2017-09-05 14:21:22 · 197 阅读 · 0 评论 -
Leetcode:611. Valid Triangle Number
Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.Example 1:In原创 2017-09-04 21:38:09 · 244 阅读 · 0 评论 -
Leetcode:621. Task Scheduler
Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each task could be原创 2017-09-04 21:23:03 · 233 阅读 · 0 评论 -
Leetcode 264. Ugly Number II
问题描述 Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the原创 2017-07-10 10:22:10 · 210 阅读 · 0 评论 -
LeetCode: 421. Maximum XOR of Two Numbers in an Array
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.Find the maximum result of ai XOR aj, where 0 ≤ i, j < n.Could you do this in O(n) runtime?Example:Input: [3, 10, 5, 25, 2,原创 2017-09-15 15:13:21 · 289 阅读 · 0 评论 -
LeetCode:406. Queue Reconstruction by Height
Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of this p原创 2017-09-07 18:22:33 · 245 阅读 · 0 评论 -
LeetCode:462. Minimum Moves to Equal Array Elements II
Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementing a selected element by 1原创 2017-09-11 10:49:50 · 242 阅读 · 0 评论 -
665. Non-decreasing Array
Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.We define an array is non-decreasing if array[i] <= array[i + 1] holds for every i原创 2017-09-01 21:59:01 · 514 阅读 · 0 评论 -
LeetCode 667. Beautiful Arrangement II
Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is [a1, a2, a3, … , an],原创 2017-09-01 20:54:23 · 757 阅读 · 0 评论 -
LeetCode:260. Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums = [1原创 2017-09-09 17:31:21 · 248 阅读 · 0 评论 -
LeetCode: 672. Bulb Switcher II
There is a room with n lights which are turned on initially and 4 buttons on the wall. After performing exactly m unknown operations towards buttons, you need to return how many different kinds of st转载 2017-09-17 22:25:53 · 357 阅读 · 0 评论 -
LeetCode:445. Add Two Numbers II
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it原创 2017-09-15 19:46:29 · 228 阅读 · 0 评论 -
LeetCode: 22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()())", "(())()", "()(())", "(原创 2017-09-17 21:44:25 · 283 阅读 · 0 评论 -
LeetCode:539. Minimum Time Difference
Given a list of 24-hour clock time points in “Hour:Minutes” format, find the minimum minutes difference between any two time points in the list. Example 1:Input: ["23:59","00:00"]Output: 1Note:The nu原创 2017-09-15 21:01:06 · 352 阅读 · 0 评论 -
LeetCode: 498. Diagonal Traverse
Given a matrix of M x N elements (M rows, N columns), return all elements of the matrix in diagonal order as shown in the below image. Example:Input:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]Outp原创 2017-09-15 20:27:33 · 335 阅读 · 0 评论 -
LeetCode:526. Beautiful Arrangement
Suppose you have N integers from 1 to N. We define a beautiful arrangement as an array that is constructed by these N numbers successfully if one of the following is true for the ith position (1 <= i <原创 2017-09-07 20:43:15 · 318 阅读 · 0 评论 -
LeetCode:553. Optimal Division
Given a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -> 2 / 3 / 4.However, you can add any number of parenthesis at any position to change the原创 2017-09-07 20:06:27 · 395 阅读 · 0 评论 -
LeetCode:647. Palindromic Substrings
Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist of原创 2017-09-07 19:12:04 · 245 阅读 · 0 评论 -
Leetcode 221. Maximal Square
问题描述 Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11原创 2017-07-08 19:11:12 · 188 阅读 · 0 评论 -
Leetcode 472. Concatenated Words
问题描述: Given a list of words (without duplicates), please write a program that returns all concatenated words in the given list of words.A concatenated word is defined as a string that is compr原创 2017-06-28 14:53:13 · 373 阅读 · 0 评论 -
Leetcode 343. Integer Break
问题描述 Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n转载 2017-06-30 17:42:14 · 219 阅读 · 0 评论 -
Leetcode 354. Russian Doll Envelopes
问题描述 You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envelope can fit into another if and only if both the width and height of one envelope is gre原创 2017-06-30 17:09:26 · 341 阅读 · 0 评论 -
Leetcode 174. Dungeon Game
问题描述 table.dungeon, .dungeon th, .dungeon td { border:3px solid black;} .dungeon th, .dungeon td { text-align: center; height: 70px; width: 70px;}The demons had captured the p转载 2017-07-10 22:20:49 · 239 阅读 · 0 评论 -
Leetcode 188. Best Time to Buy and Sell Stock IV
问题描述 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 k transactions.Note:You may转载 2017-07-10 19:57:30 · 290 阅读 · 0 评论 -
Leetcode 357. Count Numbers with Unique Digits
问题描述 Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example:Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤原创 2017-06-30 15:59:54 · 190 阅读 · 0 评论 -
Leetcode 368. Largest Divisible Subset
问题描述 Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.If there are multiple so原创 2017-06-30 14:53:20 · 185 阅读 · 0 评论 -
Leetcode 376. Wiggle Subsequence
问题描述 A sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may b原创 2017-06-30 12:00:10 · 203 阅读 · 0 评论 -
Leetcode 377. Combination Sum IV
问题描述 Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4T原创 2017-06-30 10:50:51 · 219 阅读 · 0 评论 -
Leetcode 403. Frog Jump
问题描述 A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.Given a原创 2017-06-30 09:51:26 · 400 阅读 · 0 评论 -
Leetcode 213. House Robber II
问题描述 Note: This is an extension of House Robber.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. T原创 2017-07-10 16:00:25 · 245 阅读 · 0 评论 -
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 robbing each of them is that ad原创 2017-07-10 15:03:24 · 170 阅读 · 0 评论