走进LeetCode
文章平均质量分 51
由浅入深,from easy to hard,逐步探讨分析LeetCode上的每一道算法题,给出代码实现的同时,你能获取全新的解题思路。算法全部是用Java语言实现,希望每一篇文章都能给你带来帮助和启发,并不断提高自己。
皮斯特劳沃
目前在一家大型互联网公司工作,担任JAVA高级开发工程师,主要负责手机APP服务器端相关开发和研发。平时喜欢学习和钻研技术,对算法、代码重构、设计模型有所学习和了解。目前正在学习RPC和WebService等相关分布式技术。
展开
-
Leetcode_69_Sqrt(x)
Implement int sqrt(int x).Compute and return the square root of x.x is guaranteed to be a non-negative integer.Example 1:Input: 4 Output: 2 Example 2:Input: 8 Output: 2 Explanation: The ...原创 2018-04-13 22:59:42 · 346 阅读 · 0 评论 -
Leetcode_155_Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get t...原创 2018-04-13 22:27:50 · 330 阅读 · 0 评论 -
Leetcode_347_Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example, Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number of uniqu...原创 2018-04-09 23:09:58 · 262 阅读 · 0 评论 -
Leetcode_454_4Sum II
Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero.To make problem a bit easier, all A, B, C, D have same lengt...原创 2018-04-09 22:51:18 · 447 阅读 · 0 评论 -
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: Special thanks to @fujiaozhu for adding thi原创 2016-10-16 21:34:59 · 988 阅读 · 1 评论 -
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 random position. Find the letter that was add原创 2016-10-16 17:50:56 · 787 阅读 · 0 评论 -
Leetcode_350_Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each element in the result should appear as many ti原创 2016-08-22 21:13:01 · 1022 阅读 · 0 评论 -
Leetcode_342_Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example: Given num = 16, return true. Given num = 5, return false. Follow up: Could you solve it withou原创 2016-08-13 11:18:33 · 967 阅读 · 0 评论 -
Leetcode_292_Nim Game
You 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 last stone will be the原创 2016-06-20 22:43:01 · 2450 阅读 · 0 评论 -
Leetcode_344_Reverse String
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/50768550 Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “原创 2016-06-15 22:27:08 · 2272 阅读 · 0 评论 -
Leetcode_299_Bulls and Cows
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/50768550You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend原创 2016-02-29 21:49:45 · 1986 阅读 · 0 评论 -
Leetcode_278_First Bad Version
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/49719255You are a product manager and currently leading a team to develop a new product. Unfortunately, the l原创 2015-11-08 16:22:58 · 2068 阅读 · 0 评论 -
Leetocde_290_Word Pattern
http://blog.csdn.net/pistolove/article/details/49717803Given a pattern and a string str, find if str follows the same pattern.Here follow means a full mat原创 2015-11-08 13:00:57 · 1347 阅读 · 0 评论 -
Leetcode_257_Binary Tree Paths
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/49432057Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree:原创 2015-10-26 23:25:54 · 1471 阅读 · 0 评论 -
Leetcode_263_Ugly Number
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/49431329Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose p原创 2015-10-26 23:04:42 · 1555 阅读 · 0 评论 -
Leetocde_242_Valid Anagram
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/48979767Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "ana原创 2015-10-08 22:26:05 · 2354 阅读 · 3 评论 -
Leetcode_238_Product of Array Except Self
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/48598939Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the pr原创 2015-09-20 18:53:25 · 1355 阅读 · 0 评论 -
Leetcode_252_Implement Stack using Queues
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/48598773Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() --原创 2015-09-20 18:21:08 · 1171 阅读 · 0 评论 -
Leetcode_232_Implement Queue using Stacks
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/48392363Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop原创 2015-09-12 11:01:23 · 2080 阅读 · 0 评论 -
Leetcode_231_Power of Two
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/47334243Given an integer, write a function to determine if it is a power of two.思路:(1)题意为给定一个正整数,判断该正整数是否为2的幂。(2)该题属于Lettcode中的简单题。只需循环判断正整数N对2求余是否为0,如果不为0,返回false;如果原创 2015-08-07 09:33:06 · 1050 阅读 · 0 评论 -
Leetcode_234_Palindrome Linked List
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/47334465Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?思路:(1)题意为给定一个链表,判断该链表是否“回文”,即该链表中每原创 2015-08-07 09:44:27 · 1186 阅读 · 0 评论 -
Leetcode_237_Delete Node in a Linked List
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/47334649Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are原创 2015-08-07 09:53:09 · 1786 阅读 · 0 评论 -
Leetcode_223_Rectangle Area
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/46868363Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.A原创 2015-07-13 22:02:28 · 1643 阅读 · 0 评论 -
Leetcode_190_Reverse Bits
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/46868017Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented原创 2015-07-13 21:33:35 · 2592 阅读 · 0 评论 -
Leetcode_228_Summary Ranges
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/46762039Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].思路:(1)题意为给定原创 2015-07-05 11:07:31 · 1424 阅读 · 0 评论 -
Leetcode_205_Isomorphic Strings
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/46530865Given 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 ch原创 2015-06-17 10:27:44 · 2026 阅读 · 0 评论 -
Leetcode_204_Count Primes
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/46366207Description:Count the number of prime numbers less than a non-negative number, n.思路:(1)题意为给定整数n,求解n以内的整数中有多少个素数(质数)。(2)该题涉及到数学相关的知识。首先,看下素数的定义:质数(prime原创 2015-06-04 19:38:22 · 1250 阅读 · 0 评论 -
Leetcode_203_Remove Linked List Elements
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/45868027Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 -->原创 2015-05-20 10:57:04 · 1173 阅读 · 0 评论 -
Leetcode_206_Reverse Linked List
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/45739753 Reverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?思原创 2015-05-15 08:15:48 · 1527 阅读 · 0 评论 -
Leetcode_202_Happy Number
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/45396585Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace th原创 2015-04-30 16:35:40 · 2233 阅读 · 5 评论 -
Leetcode_191_Number of 1 Bits
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/44486547Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary原创 2015-03-20 08:11:25 · 1680 阅读 · 0 评论 -
Leetcode_48_Rotate Image
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/44216867You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?思路:(1)题意为给定一个n*原创 2015-03-12 08:48:34 · 1551 阅读 · 0 评论 -
Leetcode_34_Search for a Range
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/44021767Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(原创 2015-03-02 18:46:41 · 1229 阅读 · 0 评论 -
Leetcode_53_Maximum Subarray
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/43989997Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the原创 2015-02-28 21:01:04 · 1517 阅读 · 3 评论 -
Leetcode_128_Longest Consecutive Sequence
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/43854597Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elemen原创 2015-02-16 20:41:29 · 1223 阅读 · 0 评论 -
Leetcode_80_Remove Duplicates from Sorted Array II
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/43835055Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array原创 2015-02-15 14:37:30 · 1450 阅读 · 0 评论 -
Leetcode_123_Best Time to Buy and Sell Stock III
本文是在学习中的总结,欢迎转载但请注明出处:http://write.blog.csdn.net/postedit/43740415Say you have an array for which the ith element is the price of a given stock on day i.Design an algori原创 2015-02-11 21:15:52 · 1483 阅读 · 0 评论 -
Leetcode_35_Search Insert Position
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/43739647Given 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原创 2015-02-11 20:39:58 · 1092 阅读 · 0 评论 -
Leetcode_116_Populating Next Right Pointers in Each Node
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/43532817Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right;原创 2015-02-05 19:18:29 · 1533 阅读 · 0 评论 -
Leetcode_162_Find Peak Element
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/43415313A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The a原创 2015-02-02 21:04:13 · 1484 阅读 · 0 评论