LeetCode
文章平均质量分 52
qha0731
这个作者很懒,什么都没留下…
展开
-
LeetCode: 561. Array Partition I
561. Array Partition IGiven an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi)原创 2017-05-10 23:39:45 · 365 阅读 · 0 评论 -
LeetCode: 496. Next Greater Element I
LeetCode: 496. Next Greater Element I You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1’s ele原创 2017-07-06 09:49:22 · 368 阅读 · 0 评论 -
LeetCode: 292. Nim Game
LeetCode: 292. Nim GameYou are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the原创 2017-07-07 09:16:58 · 237 阅读 · 0 评论 -
LeetCode: 521. Longest Uncommon Subsequence I
LeetCode: 521. Longest Uncommon Subsequence I Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. The longest uncommon subsequence is d原创 2017-07-07 10:01:15 · 335 阅读 · 0 评论 -
LeetCode: 485. Max Consecutive Ones
LeetCode: 485. Max Consecutive Ones Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digi原创 2017-07-07 10:22:50 · 235 阅读 · 0 评论 -
LeetCode: 136. Single Number
LeetCode: 136. Single Number Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could原创 2017-07-07 10:57:39 · 345 阅读 · 0 评论 -
LeetCode: 104. Maximum Depth of Binary Tree
LeetCode: 104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthes原创 2017-07-07 11:26:56 · 339 阅读 · 0 评论 -
LeetCode: 520. Detect Capital
LeetCode: 520. Detect Capital Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when one of the fol原创 2017-07-07 14:00:46 · 225 阅读 · 0 评论 -
LeetCode: 606. Construct String from Binary Tree
LeetCode: 606. Construct String from Binary Tree You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. The null node needs t原创 2017-07-07 15:05:26 · 309 阅读 · 0 评论 -
LeetCode: 448. Find All Numbers Disappeared in an Array
LeetCode: 448. Find All Numbers Disappeared in an Array 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 elem原创 2017-07-07 15:31:56 · 256 阅读 · 0 评论 -
LeetCode: 463. Island Perimeter
LeetCode: 463. Island Perimeter You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (n原创 2017-07-06 13:33:44 · 221 阅读 · 0 评论 -
LeetCode: 389. Find the Difference
LeetCode: 389. Find the Difference 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 rand原创 2017-07-07 16:15:19 · 240 阅读 · 0 评论 -
LeetCode: 226. Invert Binary Tree
LeetCode: 226. Invert Binary Tree Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem was inspired by this original原创 2017-07-07 16:36:18 · 208 阅读 · 0 评论 -
LeetCode: 371. Sum of Two Integers
LeetCode: 371. Sum of Two Integers Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Example: Given a = 1 and b = 2, return 3. Credits: Spec原创 2017-07-07 17:32:16 · 221 阅读 · 0 评论 -
LeetCode: 442. Find All Duplicates in an Array
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 appe原创 2017-07-10 10:25:21 · 228 阅读 · 0 评论 -
LeetCode: 268. Missing Number
LeetCode: 268. Missing Number 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.原创 2017-07-10 11:13:45 · 205 阅读 · 0 评论 -
LeetCode: 35. Search Insert Position
LeetCode: 35. Search Insert Position 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.原创 2017-07-14 13:48:20 · 306 阅读 · 0 评论 -
LeetCode: 412. Fizz Buzz
LeetCode: 412. Fizz Buzz Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the number and for t原创 2017-07-05 16:10:00 · 223 阅读 · 0 评论 -
LeetCode: 344. Reverse String
LeetCode: 344. Reverse String Write a function that takes a string as input and returns the string reversed. Example: Given s = “hello”, return “olleh”.public class Solution { public Str原创 2017-07-05 15:09:17 · 230 阅读 · 0 评论 -
LeetCode: 461. Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Given two integers x and y, calculate the Hamming distance.Note:0 ≤ x,原创 2017-05-12 00:12:32 · 294 阅读 · 0 评论 -
LeetCode: 476. Number Complement
LeetCode: 476. Number Complement Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Note: The given integer is guar原创 2017-06-29 16:53:05 · 242 阅读 · 0 评论 -
LeetCode: 617. Merge Two Binary Trees
LeetCode: 617. Merge Two Binary Trees 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.原创 2017-06-29 17:03:35 · 264 阅读 · 0 评论 -
LeetCode: 557. Reverse Words in a String III
LeetCode: 557. Reverse Words in a String III Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.原创 2017-06-30 14:29:02 · 321 阅读 · 0 评论 -
LeetCode: 500. Keyboard Row
LeetCode: Add to List 500. Keyboard Row Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard like the image below. Ame原创 2017-06-30 16:37:16 · 242 阅读 · 0 评论 -
LeetCode: 566. Reshape the Matrix
LeetCode: 566. Reshape the Matrix 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原创 2017-06-30 17:27:17 · 238 阅读 · 0 评论 -
LeetCode: 283. Move Zeroes
LeetCode: 283. Move Zeroes 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. For example, given nums = [0,原创 2017-07-11 09:38:09 · 210 阅读 · 0 评论 -
LeetCode: 167. Two Sum II - Input array is sorted
LeetCode: 167. Two Sum II - Input array is sorted 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原创 2017-07-11 09:41:34 · 245 阅读 · 0 评论 -
LeetCode: 169. Majority Element
LeetCode: 169. Majority Element 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原创 2017-07-11 09:43:37 · 230 阅读 · 0 评论 -
LeetCode: 189. Rotate Array
LeetCode: 189. Rotate Array Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note: Try t原创 2017-07-12 10:54:02 · 222 阅读 · 0 评论 -
LeetCode: 26. Remove Duplicates from Sorted Array
LeetCode: 26. Remove Duplicates from Sorted Array Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra原创 2017-07-12 11:20:45 · 255 阅读 · 0 评论 -
LeetCode: 27. Remove Element
LeetCode: 27. Remove Element Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this原创 2017-07-12 14:26:02 · 367 阅读 · 0 评论 -
LeetCode: 605. Can Place Flowers
LeetCode: 605. Can Place Flowers 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 com原创 2017-07-12 14:59:40 · 386 阅读 · 0 评论 -
LeetCode: 217. Contains Duplicate
LeetCode: 217. Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and i原创 2017-07-12 15:18:02 · 310 阅读 · 0 评论 -
LeetCode: 575. Distribute Candies
LeetCode: 575. Distribute Candies 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 corresp原创 2017-07-05 14:35:46 · 234 阅读 · 0 评论 -
LeetCode: 1. Two Sum
LeetCode: 1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution,原创 2017-07-10 14:14:56 · 274 阅读 · 0 评论