![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode算法
文章平均质量分 81
Crab0314
这个作者很懒,什么都没留下…
展开
-
【Leetcode】665. Non-decreasing Array(Easy)
1.题目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...原创 2018-04-26 16:17:43 · 349 阅读 · 0 评论 -
【Leetcode】605. Can Place Flowers(Easy)
1.题目Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.Gi...原创 2018-03-27 10:10:16 · 417 阅读 · 0 评论 -
【Leetcode】595. Big Countries(Easy)
1.题目There is a table World+-----------------+------------+------------+--------------+---------------+| name | continent | area | population | gdp |+-----------------+-...原创 2018-03-22 11:20:40 · 248 阅读 · 0 评论 -
【Leetcode】598. Range Addition II(Easy)
1.题目Given an m * n matrix M initialized with all 0's and several update operations.Operations are represented by a 2D array, and each operation is represented by an array with two positive integers a ...原创 2018-03-22 11:03:41 · 183 阅读 · 0 评论 -
【Leetcode】594. Longest Harmonious Subsequence (Easy)
1.题目We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1.Now, given an integer array, you need to find the length of its longest h...原创 2018-03-21 12:25:19 · 205 阅读 · 0 评论 -
【Leetcode】581. Shortest Unsorted Continuous Subarray(Easy)
1.题目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 fin...原创 2018-03-20 10:25:56 · 188 阅读 · 0 评论 -
【Leetcode】575. Distribute Candies(Easy)
1.题目Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of the corresponding kind. You need to dist原创 2018-03-20 10:07:10 · 161 阅读 · 0 评论 -
【Leetcode】596. Classes More Than 5 Students(Easy)
1.题目There is a table courses with columns: student and classPlease list out all classes which have more than or equal to 5 students.For example, the table:+---------+------------+| student | class ...原创 2018-03-23 15:55:52 · 244 阅读 · 0 评论 -
【Leetcode】599. Minimum Index Sum of Two Lists(Easy)
1.题目Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.You need to help them find out their common interest with th...原创 2018-03-23 15:50:20 · 208 阅读 · 0 评论 -
【Leetcode】551. Student Attendance Record I(Easy)
1.题目You are given a string representing an attendance record for a student. The record only contains the following three characters:'A' : Absent.'L' : Late.'P' : Present.A student could be rewarded if...原创 2018-03-06 10:42:24 · 195 阅读 · 0 评论 -
【Leetcode】543. Diameter of Binary Tree(Easy)
1.题目Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path may or m...原创 2018-03-06 10:32:28 · 268 阅读 · 0 评论 -
【Leetcode】606. Construct String from Binary Tree(Easy)
1.题目You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null node needs to be represented by empty parenthesis pair "()". And yo...原创 2018-03-27 10:17:45 · 194 阅读 · 0 评论 -
【Leetcode】617. Merge Two Binary Trees(Easy)
1.题目Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tr...原创 2018-03-28 10:31:48 · 166 阅读 · 0 评论 -
【Leetcode】661. Image Smoother(Easy)
1.题目Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down) of all the 8 s...原创 2018-04-24 15:49:39 · 217 阅读 · 0 评论 -
【Leetcode】657. Judge Route Circle(Easy)
1.题目Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place.The move sequence is represented ...原创 2018-04-24 14:26:10 · 162 阅读 · 0 评论 -
【Leetcode】653. Two Sum IV - Input is a BST(Easy)
1.题目Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.Example 1:Input: 5 / \ 3 6 / \ \...原创 2018-04-23 10:16:19 · 171 阅读 · 0 评论 -
【Leetcode】645. Set Mismatch(Easy)
1.题目The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another number in the set, which results in repetition ...原创 2018-03-29 11:02:49 · 467 阅读 · 0 评论 -
【Leetcode】643. Maximum Average Subarray I(Easy)
1.题目Given an array consisting of n integers, find the contiguous subarray of given length k that has the maximum average value. And you need to output the maximum average value.Example 1:Input: [1,12,...原创 2018-03-29 10:44:45 · 202 阅读 · 0 评论 -
【Leetcode】637. Average of Levels in Binary Tree(Easy)
1.题目Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.Example 1:Input: 3 / \ 9 20 / \ 15 7Output: [3, 14.5, 11]Explanatio...原创 2018-03-29 10:36:09 · 208 阅读 · 0 评论 -
【Leetcode】633. Sum of Square Numbers(Easy)
1.题目Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c.翻译:给定一个非负整数 c ,你的任务是判断是否有两个整数 a 和 b ,使得a2 + b2 = c.Example 1:Input: 5Output: Tru...原创 2018-03-28 10:59:22 · 244 阅读 · 0 评论 -
【Leetcode】628. Maximum Product of Three Numbers(Easy)
1.题目Given an integer array, find three numbers whose product is maximum and output the maximum product.翻译:给定一个整数序列,找到三个数使得它们的乘积最大,并且输出最大的乘积。Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4...原创 2018-03-28 10:50:52 · 304 阅读 · 0 评论 -
【Leetcode】627. Swap Salary(Easy)
1.题目Given a table salary, such as the one below, that has m=male and f=female values. Swap all f and m values (i.e., change all f values to m and vice versa) with a single update query and no intermed...原创 2018-03-28 10:44:36 · 266 阅读 · 0 评论 -
【Leetcode】620. Not Boring Movies(Easy)
1.题目X city opened a new cinema, many people would like to go to this cinema. The cinema also gives out a poster indicating the movies’ ratings and descriptions.Please write a SQL query to output movie...原创 2018-03-28 10:38:17 · 275 阅读 · 0 评论 -
【Leetcode】541. Reverse String II(Easy)
1.题目Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of ...原创 2018-03-05 13:59:56 · 219 阅读 · 0 评论 -
【Leetcode】538. Convert BST to Greater Tree(Easy)
1.题目Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.Exam...原创 2018-03-05 13:33:32 · 244 阅读 · 0 评论 -
【Leetcode】458. Poor Pigs(Easy)
1.题目There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. They all look the same. If a pig drinks that poison it will die within 15 minutes. What is the min...原创 2018-02-11 14:45:59 · 302 阅读 · 0 评论 -
【Leetcode】443. String Compression (Easy)
1.题目Given an array of characters, compress it in-place.The length after compression must always be smaller than or equal to the original array.Every element of the array should be a character (not int...原创 2018-02-06 21:45:57 · 504 阅读 · 0 评论 -
【Leetcode】196. Delete Duplicate Emails (Easy)
1.题目Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.翻译:写一个SQL语句删掉Person表中,所有email重复的实体(相同的保留一个),只保留I的最小的唯原创 2018-02-02 16:56:16 · 280 阅读 · 0 评论 -
【Leetcode】183. Customers Who Never Order (Easy)
1.题目Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never order anything.翻译:假设一个网站包含两个表,Customers表和Orders表原创 2018-02-02 16:26:12 · 352 阅读 · 0 评论 -
【Leetcode】182. Duplicate Emails (Easy)
1.题目Write a SQL query to find all duplicate emails in a table named Person.翻译:写一个SQL查询语句,找出Person表中所有重复的Email。+----+---------+| Id | Email |+----+---------+| 1 | a@b.com || 2 | c@d原创 2018-02-02 16:17:09 · 246 阅读 · 0 评论 -
【Leetcode】35. Search Insert Position (Easy)
1.题目Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in原创 2018-02-01 17:06:54 · 198 阅读 · 0 评论 -
【Leetcode】181. Employees Earning More Than Their Managers (Easy)
1.题目The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.+----+-------+--------+-----------+| Id | Name原创 2018-02-01 17:40:23 · 244 阅读 · 0 评论 -
【Leetcode】176. Second Highest Salary (Easy)
1.题目Write a SQL query to get the second highest salary from the Employee table.+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 300 |+----+--------+原创 2018-02-01 12:43:02 · 284 阅读 · 0 评论 -
【Leetcode】175. Combine Two Tables(Easy)
1.题目Table: Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName | varchar |+-------------+----原创 2018-02-01 12:25:23 · 496 阅读 · 0 评论 -
【Leetcode】167. Two Sum II - Input array is sorted(Easy)
1.题目Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the原创 2018-02-01 12:05:51 · 266 阅读 · 0 评论 -
【Leetcode】122. Best Time to Buy and Sell Stock II(Easy)
1.题目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 (原创 2018-01-30 14:52:06 · 175 阅读 · 0 评论 -
【Leetcode】108. Convert Sorted Array to Binary Search Tree(Easy)
1.题目Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the de原创 2018-01-30 14:43:49 · 178 阅读 · 0 评论 -
【Leetcode】532. K-diff Pairs in an Array(Easy)
1.题目Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both number...原创 2018-02-23 18:20:58 · 200 阅读 · 0 评论 -
【Leetcode】572. Subtree of Another Tree(Easy)
1.题目Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this ...原创 2018-03-09 11:33:46 · 204 阅读 · 0 评论 -
【Leetcode】566. Reshape the Matrix(Easy)
1.题目In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.You're given a matrix represented by a two-dim...原创 2018-03-09 11:27:09 · 182 阅读 · 0 评论