LeetCode
Coder微观
这个作者很懒,什么都没留下…
展开
-
Leetcode_Array -- 888. Fair Candy Swap [easy]
Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that Alice has, and B[j] is the size of the j-th bar of candy that Bob has.Since they are friends, they wo...原创 2018-11-20 20:35:09 · 112 阅读 · 0 评论 -
Leetcode_Array -- 747. Largest Number At Least Twice of Others [easy]
In a given integer array nums, there is always exactly one largest element.Find whether the largest element in the array is at least twice as much as every other number in the array.If it is, r...原创 2018-11-08 21:03:05 · 96 阅读 · 0 评论 -
Leetcode_Array -- 674. Longest Continuous Increasing Subsequence [easy]
Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray).给定一个未排序的整数数组,找到最长的连续递增子序列,返回其长度Example 1:Input: [1,3,5,4,7]Output: 3Explanation: T...原创 2018-11-07 21:43:03 · 143 阅读 · 0 评论 -
Leetcode_Array -- 169. Majority Element [easy]
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element alwa...原创 2018-11-07 20:43:04 · 97 阅读 · 0 评论 -
Leetcode_Array -- 643. Maximum Average Subarray I [easy]
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.给定一个整数组成的数组,找到长度为k的连续子数组,...原创 2018-11-05 22:00:57 · 112 阅读 · 0 评论 -
Leetcode_Array -- 628. Maximum Product of Three Numbers [easy]
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,...原创 2018-11-04 14:40:33 · 134 阅读 · 0 评论 -
Leetcode_Array -- 532. K-diff Pairs in an Array [easy]
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 numbers in...原创 2018-11-12 23:20:11 · 106 阅读 · 0 评论 -
Leetcode_Array -- 485. Max Consecutive Ones [easy]
Given a binary array, find the maximum number of consecutive 1s in this array.给定一个二进制数组(只包含0,1),找到连续出现1最大的子数组,求其长度。Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or ...原创 2018-11-06 21:49:34 · 106 阅读 · 0 评论 -
Leetcode_Array -- 53. Maximum Subarray [easy]
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.给定一个整数数组nums,找到nums拥有最大和的连续子数组,返回这个和Example:Input: [-2,1,...原创 2018-11-03 21:10:38 · 109 阅读 · 0 评论 -
Leetcode_Array -- 88. Merge Sorted Array [easy]
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.给定两个排好序的整数数组nums1和nums2,将nums2合并到nums1中,成为一个排好序的数组Note:The number of elements initialized in nums1 and...原创 2018-11-03 15:10:03 · 127 阅读 · 0 评论 -
Leetcode_Array -- 66. Plus One [easy]
Given a non-empty array of digits representing a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each element ...原创 2018-10-27 19:02:25 · 103 阅读 · 0 评论 -
Leetcode_Array --189. Rotate Array [easy]
Given an array, rotate the array to the right by k steps, where k is non-negative.给定一个数组,将数组向右扭转k步,k是非负的Example 1:Input: [1,2,3,4,5,6,7] and k = 3Output: [5,6,7,1,2,3,4]Explanation:rotate 1 step...原创 2018-10-24 22:23:47 · 114 阅读 · 0 评论 -
Leetcode_Array --35. Search Insert Position [easy]
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.给定一个排好序的数组和一个目标值,如果目标值在数组中,返回目标值的索引,如果目标值不在数组...原创 2018-10-24 20:07:47 · 98 阅读 · 0 评论 -
Leetcode_Array --581. Shortest Unsorted Continuous Subarray [easy]
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.给定一个整数数组,找到一个连续子数组...原创 2018-10-24 17:25:29 · 133 阅读 · 0 评论 -
Leetcode_Array --905. Sort Array By Parity [easy]
Given an array A of non-negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A.给定一个非负整数数组A,请返回一个数组,这个数组的前面是A中的偶数,偶数后面跟着A中的奇数You may return...原创 2018-10-24 10:37:43 · 240 阅读 · 0 评论 -
Leetcode_Array -- 697. Degree of an Array [easy]
Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.Your task is to find the smallest possible length of a ...原创 2018-11-21 23:18:16 · 122 阅读 · 0 评论 -
Leetcode_Array -- 448. Find All Numbers Disappeared in an Array [easy]
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this array.Coul...原创 2018-11-20 09:24:59 · 74 阅读 · 0 评论 -
Leetcode_Dynamic_Programming -- 91. Decode Ways [medium]
A message containing letters fromA-Zis being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given anon-emptystring containing only digits, determine th...原创 2019-04-27 23:03:11 · 106 阅读 · 0 评论 -
Leetcode_Dynamic_Programming -- 322. Coin Change [medium]
You are given coins of different denominations and a total amount of moneyamount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money ...原创 2019-04-19 16:47:09 · 99 阅读 · 0 评论 -
Leetcode_Dynamic_Programming -- 198. House Robber [easy]
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 adjacent house...原创 2019-04-15 08:38:15 · 100 阅读 · 0 评论 -
Leetcode_Dynamic_Programming -- 5. Longest Palindromic Substring [medium]
Given a strings, find the longest palindromic substring ins. You may assume that the maximum length ofsis 1000.给定一个字符串s,找到s的最长回文子串,假设s的最大长度是1000Example 1:Input: "babad"Output: "bab"Note: ...原创 2019-04-21 17:03:33 · 80 阅读 · 0 评论 -
Leetcode_Dynamic_Programming -- 746. Min Cost Climbing Stairs [easy]
On a staircase, thei-th step has some non-negative costcost[i]assigned (0 indexed).Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of ...原创 2019-04-14 22:18:54 · 144 阅读 · 0 评论 -
Leetcode_Dynamic_Programming -- 300. Longest Increasing Subsequence [medium]
Given an unsorted array of integers, find the length of longest increasing subsequence.给定一个未排序的整数数组,返回该数组的最长递增子序列的长度。Example:Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest inc...原创 2019-04-21 11:32:58 · 105 阅读 · 0 评论 -
Leetcode_Dynamic_Programming -- 70. Climbing Stairs [easy]
You are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note:Givennwill be a positive...原创 2019-04-12 15:48:57 · 114 阅读 · 0 评论 -
Leetcode_Dynamic_Programming --121. Best Time to Buy and Sell Stock [easy]
Say you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock),...原创 2019-04-12 14:26:37 · 148 阅读 · 0 评论 -
Leetcode_Linked_List --19. Remove Nth Node From End of List [medium]
Given a linked list, remove then-th node from the end of list and return its head.给定一个单向链表,移除从链表的尾节点开始数的第n个节点并返回链表Example:Given linked list: 1->2->3->4->5, and n = 2.After removi...原创 2019-03-05 07:56:29 · 82 阅读 · 0 评论 -
Leetcode_Linked_List --24. Swap Nodes in Pairs [medium]
Given alinked list, swap every two adjacent nodes and return its head.You maynotmodify the values in the list's nodes, only nodes itself may be changed.给定一个链表,交换每两个相邻节点,并返回其头部节点你不能改变链表中的值,只能改...原创 2019-03-04 22:07:19 · 101 阅读 · 0 评论 -
Leetcode_Linked_List --2. Add Two Numbers [medium]
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...原创 2019-02-16 17:59:34 · 135 阅读 · 0 评论 -
Leetcode_Array -- 724. Find Pivot Index [easy]
Given an array of integers nums, write a method that returns the "pivot" index of this array.We define the pivot index as the index where the sum of the numbers to the left of the index is equal to ...原创 2018-11-17 15:14:10 · 112 阅读 · 0 评论 -
Leetcode_Array -- 832. Flipping an Image [easy]
Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image.To flip an image horizontally means that each row of the image is reversed. For examp...原创 2018-11-17 13:57:40 · 115 阅读 · 0 评论 -
Leetcode_Array -- 268. Missing Number [easy]
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.给定一个包含n个不同的数字的数组,找到这个数组中从0到n缺少的数这里需要解释一下n个数的数组只能装下n-1个数!即三个数的组数[3,1,2],其缺少的数字是0...原创 2018-10-27 19:30:39 · 89 阅读 · 0 评论 -
Leetcode_Array -- 283. Move Zeroes [easy]
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.给定一个数组nums,编写一个函数,将数组中的0都移动到数组末尾,保持数组中非0元素的相对顺序。Example:Inpu...原创 2018-10-26 14:29:57 · 83 阅读 · 0 评论 -
Leetcode_Array -- 830. Positions of Large Groups [easy]
In a string S of lowercase letters, these letters form consecutive groups of the same character.For example, a string like S = "abbxxxxzyy" has the groups "a", "bb", "xxxx", "z" and "yy".Call原创 2018-10-26 11:08:27 · 79 阅读 · 0 评论 -
Leetcode_Linked_List --203. Remove Linked List Elements [easy]
Remove all elements from a linked list of integers that have value val.删除链表中值为val的所有元素Example:Input: 1->2->6->3->4->5->6, val = 6Output: 1->2->3->4-原创 2018-10-13 15:39:21 · 89 阅读 · 0 评论 -
Leetcode_Linked_List --206. Reverse Linked List [easy]
Reverse a singly linked list.反转一个单链表Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3-&原创 2018-10-13 12:11:37 · 79 阅读 · 0 评论 -
Leetcode_Heap --373. Find K Pairs with Smallest Sums [medium]
You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.Define a pair (u,v) which consists of one element from the first array and one element from the second arra...原创 2018-09-28 14:43:17 · 83 阅读 · 0 评论 -
Leetcode_Sort --524. Longest Word in Dictionary through Deleting [medium]
Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, retur...原创 2018-09-22 17:17:25 · 139 阅读 · 0 评论 -
Leetcode_Heap --347. Top K Frequent Elements [medium]
Given a non-empty array of integers, return the k most frequent elements.给定一个非空的整数数组,返回频率最高的k个元素Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Outpu...原创 2018-09-27 15:09:57 · 88 阅读 · 0 评论 -
Leetcode_Heap --692. Top K Frequent Words [medium]
Given a non-empty list of words, return the k most frequent elements.Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the low...原创 2018-09-26 21:46:36 · 114 阅读 · 0 评论 -
Leetcode_Sort --147. Insertion Sort List [medium]
Sort a linked list using insertion sort.A graphical example of insertion sort. The partial sorted list (black) initially contains only the first element in the list.With each iteration one element ...原创 2018-09-26 15:53:08 · 119 阅读 · 0 评论