leetcode
文章平均质量分 61
momottyy
这个作者很懒,什么都没留下…
展开
-
【Javascript】leetcode 18.4Sum
Given an arraynumsofnintegers and an integertarget, are there elementsa,b,c, anddinnumssuch thata+b+c+d=target? Find all unique quadruplets in the array which gives the sum oftarget.Note:The solution set must not contain duplicat...原创 2020-05-11 22:10:11 · 231 阅读 · 0 评论 -
【Javascript】leetcode 15. 3Sum
Given an arraynumsofnintegers, are there elementsa,b,cinnumssuch thata+b+c= 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not contain duplicate triplets.Example:Given array nums = ...原创 2020-05-11 20:11:29 · 195 阅读 · 0 评论 -
【leetcode】1 两数之和 (c++)
题目链接 第一次做leetcode。。有点手足无措。。给定一个整数数组和一个目标值,找出数组中和为目标值的两个数。你可以假设每个输入只对应一种答案,且同样的元素不能被重复利用。示例:给定 nums = [2, 7, 11, 15], target = 9因为 nums[0] + nums[1] = 2 + 7 = 9所以返回 [0, 1]class Solution {public: ...原创 2018-06-14 19:36:46 · 784 阅读 · 2 评论 -
【leetcode】7 反转整数 (c++)
题目链接给定一个 32 位有符号整数,将整数中的数字进行反转。示例 1:输入: 123输出: 321 示例 2:输入: -123输出: -321示例 3:输入: 120输出: 21注意:假设我们的环境只能存储 32 位有符号整数,其数值范围是 [−231, 231 − 1]。根据这个假设,如果反转后的整数溢出,则返回 0。感觉leetcode和pat不一样的地方在于不能钻printf...原创 2018-06-15 15:50:55 · 905 阅读 · 0 评论 -
【leetcode】9 回文数
判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。示例 1:输入: 121输出: true示例 2:输入: -121输出: false解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。示例 3:输入: 10输出: false解释: 从右向左读, 为 01 。因此它不是一个回文数。进阶:你能不将整数转为字...原创 2018-06-16 14:36:41 · 429 阅读 · 0 评论 -
【leetcode】53. Maximum Subarray
原题链接Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Ex...原创 2018-08-01 14:39:02 · 204 阅读 · 0 评论 -
【leetcode】300. Longest Increasing Subsequence(c/c++)
原题链接Given an unsorted array of integers, find the length of longest increasing subsequence.Example: Input:[10,9,2,5,3,7,101,18]Output: 4Explanation: The longest increasing subsequence is[2,3...原创 2018-08-01 21:35:27 · 494 阅读 · 0 评论 -
【leetcode】121. Best Time to Buy and Sell Stock(c/c++,easy难度)
原题链接 easySay 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 (i.e., buy one and sell one share o...原创 2018-08-02 13:50:08 · 309 阅读 · 0 评论 -
【leetcode】122. Best Time to Buy and Sell Stock II (c/c++,easy难度)
原题链接 easySay 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-08-02 15:32:16 · 262 阅读 · 0 评论 -
【leetcode】123. Best Time to Buy and Sell Stock III(c/c++,hard难度)
原题链接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 ma...原创 2018-08-03 14:03:46 · 820 阅读 · 0 评论 -
【leetcode】38. Count and Say(c/c++,easy难度)
原题链接 easyThe count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 ...原创 2018-08-07 17:52:18 · 137 阅读 · 0 评论 -
【leetccode】66. Plus One(c/c++,easy难度)
原题链接 easyGiven 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 ...原创 2018-08-03 15:22:02 · 206 阅读 · 0 评论 -
【leetcode】49. Group Anagrams(c/c++,medium难度)
原题链接 MediumGiven an array of strings, group anagrams together.Example:Input:["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"],原创 2018-08-08 10:57:24 · 334 阅读 · 0 评论 -
【leetcode】120.triangle(c/c++,medium难度)
题目链接 mediumGiven 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[ [2], ...原创 2018-08-27 14:51:51 · 310 阅读 · 0 评论 -
【python3】leetcode 268. Missing Number (easy)
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.Example 1:Input: [3,0,1]Output: 2Example 2:...原创 2018-12-12 17:47:38 · 150 阅读 · 0 评论 -
【python3】leetcode 88. Merge Sorted Array (easy)
88. Merge Sorted Array (easy)Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n ...原创 2018-12-12 18:22:40 · 208 阅读 · 0 评论 -
【python3】leetcode 724. Find Pivot Index (easy)
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...原创 2018-12-12 20:26:25 · 182 阅读 · 0 评论 -
【python3】leetcode 896. Monotonic Array (easy)
896. Monotonic Array (easy)An array is monotonic if it is either monotone increasing or monotone decreasing.An array A is monotone increasing if for all i <= j, A[i] <= A[j]. An array A is...原创 2018-12-12 20:35:27 · 129 阅读 · 0 评论 -
【python3】leetcode 953. Verifying an Alien Dictionary (easy)
953. Verifying an Alien Dictionary (easy)In an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some permutation...原创 2018-12-19 15:02:32 · 326 阅读 · 0 评论 -
【python3】leetcode 674. Longest Continuous Increasing Subsequence(easy)
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]Ou...原创 2018-12-13 17:46:24 · 244 阅读 · 0 评论 -
【python3】leetcode 888. Fair Candy Swap(easy)
888. Fair Candy Swap(easy) ALice要给bob一堆糖果,bob要给alice一堆,最后两人糖果总数要相同,假设alice给的那堆有a个,bob给的那堆有b个解方程吧~~ sum(A)-a+b = sum(b) - b + a -> b = a + (sum(A) + sum(B)) / 2 = a + x ...原创 2018-12-13 19:52:38 · 223 阅读 · 0 评论 -
【python3】leetcode 414. Third Maximum Numberr (easy)
414. Third Maximum Numberr (easy)一、返回第三大的数字,第一想法就是要排序用了一个magic method class Solution: def thirdMax(self, nums): """ :type nums: List[int] :rtype: int """...原创 2018-12-13 20:44:32 · 181 阅读 · 0 评论 -
【python3】leetcode 387. First Unique Character in a String(easy)
387. First Unique Character in a String(easy)Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1.Examples:s = "leetcode"return 0...原创 2018-12-19 15:43:04 · 172 阅读 · 1 评论 -
【python3】leetcode 448. Find All Numbers Disappeared in an Array(easy)
leetcode 448. Find All Numbers Disappeared in an Array(easy)本来想天秀一把 直接用listcomp语句return return [i for i in range(1,len(num)+1) if i not in nums]然而超时哈哈哈。。。。:(。。。。只能拆开写啦,set之后length会变所以先存一个变量...原创 2018-12-13 20:48:29 · 203 阅读 · 0 评论 -
【python3】leetcode 485. Max Consecutive Onesr (easy)
485. Max Consecutive Onesr (easy)Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the...原创 2018-12-13 21:10:05 · 212 阅读 · 0 评论 -
【python3】leetcode 811. Subdomain Visit Count(easy)
811. Subdomain Visit Count(easy)A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the l...原创 2018-12-19 17:04:44 · 201 阅读 · 0 评论 -
【python3】leetcode 771. Jewels and Stones(easy)
771. Jewels and StonesYou're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to...原创 2018-12-19 17:25:10 · 221 阅读 · 0 评论 -
【python3】leetcode 575. Distribute Candies(easy)
575. Distribute CandiesGiven 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. Yo...原创 2018-12-19 17:57:40 · 122 阅读 · 0 评论 -
【python3】leetcode 905. Sort Array By Parity(easy)
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.You may return any answer...原创 2018-12-14 00:38:39 · 116 阅读 · 0 评论 -
【python3】leetcode 747. Largest Number At Least Twice of Others(easy)
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 muc...原创 2018-12-14 08:36:36 · 180 阅读 · 0 评论 -
【python3】leetcode 830. Positions of Large Groups(easy)
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...原创 2018-12-14 09:21:13 · 306 阅读 · 0 评论 -
【python3】leetcode 914. X of a Kind in a Deck of Cards (easy)
914. X of a Kind in a Deck of Cards (easy)In a deck of cards, each card has an integer written on it.Return true if and only if you can choose X >= 2 such that it is possible to split the ent...原创 2018-12-14 11:56:40 · 379 阅读 · 2 评论 -
【python3】leetcode 219. Contains Duplicate II(easy)
219. Contains Duplicate II(easy)Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute diffe...原创 2018-12-19 19:46:31 · 172 阅读 · 0 评论 -
【python3】leetcode 205. Isomorphic Strings (easy)
205. Isomorphic Strings (easy)Given two strings s and t, determine if they are isomorphic.Two strings are isomorphic if the characters in s can be replaced to get t.All occurrences of a charact...原创 2018-12-19 20:34:09 · 242 阅读 · 0 评论 -
【python3】leetcode 389. Find the Difference (easy)
389. Find the Difference (easy)Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random posit...原创 2018-12-20 00:17:45 · 238 阅读 · 0 评论 -
【python3】leetcode 781. Rabbits in Forest (medium)
781. Rabbits in Forest (medium)In a forest, each rabbit has some color. Some subset of rabbits (possibly all of them) tell you how many other rabbits have the same color as them. Those answers are ...原创 2018-12-20 00:48:02 · 198 阅读 · 0 评论 -
【python3】leetcode 922. Sort Array By Parity II (easy)
922. Sort Array By Parity II (easy)Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even.Sort the array so that whenever A[i] is odd, i i...原创 2018-12-14 14:45:15 · 206 阅读 · 0 评论 -
【python3】leetcode 867. Transpose Matrix (easy)
867. Transpose Matrix Given a matrix A, return the transpose of A.The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column indices of the matrix. ...原创 2018-12-14 15:59:03 · 146 阅读 · 0 评论 -
【python3】leetcode 832. Flipping an Image(easy)
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 th...原创 2018-12-14 16:11:48 · 115 阅读 · 0 评论 -
【python3】leetcode 941. Valid Mountain Array(easy)
941. Valid Mountain Array(easy) Given an array A of integers, return true if and only if it is a valid mountain array.Recall that A is a mountain array if and only if:A.length >= 3 There ex...原创 2018-12-14 16:47:56 · 184 阅读 · 0 评论