
LeetCode例题详解
介绍LeetCode中例题的分析、解释和少量的测试用例。
styshoo
这个作者很懒,什么都没留下…
展开
-
【LeetCode】476. Number Complement (java实现)
原题链接https://leetcode.com/problems/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 int原创 2017-01-26 06:59:38 · 3055 阅读 · 1 评论 -
【LeetCode】461. Hamming Distance (java实现)
原题链接https://leetcode.com/problems/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, calcu原创 2017-01-05 22:51:29 · 5013 阅读 · 0 评论 -
【LeetCode】205 Isomorphic Strings (c++实现)
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 character must be replaced with another原创 2015-07-22 10:29:55 · 1180 阅读 · 0 评论 -
【LeetCode】475. Heaters (java实现)
原题链接https://leetcode.com/problems/heaters/原题Winter is coming! Your first job during the contest is to design a standard heater with fixed warm radius to warm all the houses.Now, you are given positions原创 2016-12-28 23:07:53 · 3706 阅读 · 0 评论 -
【LeetCode】19 Remove Nth Node From End of List (c++实现)
Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the li原创 2015-07-22 10:29:58 · 860 阅读 · 0 评论 -
【LeetCode】20 Valid Parentheses (c++实现)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all valid bu原创 2015-07-22 10:30:00 · 782 阅读 · 0 评论 -
【LeetCode】268 Missing Number (java实现)
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.Note:Your algorithm should run原创 2015-08-29 12:28:01 · 1720 阅读 · 0 评论 -
【LeetCode】141 Linked List Cycle (java实现)
Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 题目很明确,给定一个链表,判断其中是否包含一个环路。有个额外的要求就是不使用额外的空间。 假如说没有这个额外的要求,有什么方法可以解决呢?创建一个哈希表,遍历链表原创 2015-09-02 23:34:15 · 1721 阅读 · 0 评论 -
【LeetCode】如何学习LeetCode?
很多人把在LeetCode上做题称之为刷题,对于已经掌握了相关算法的人来说,这样的称呼的确没有问题,但对于那些将LeetCode作为提高自己算法能力手段的人来说,“刷题”这个称呼并不算很合适。因为做题是一个提升自己能力的途径,如果只满足于把题目做完、状态变为accept的话,并不能最有效提高编程能力。 刚开始,我也犯了上面的错误,机械的做着上面的题目,只要通过了,就不再去想其他更巧妙的方法了。尤原创 2015-09-02 23:52:09 · 7222 阅读 · 0 评论 -
【LeetCode】292 Nim Games (java实现)
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原创 2015-12-08 00:04:48 · 1006 阅读 · 0 评论 -
【LeetCode】299 Bulls and Cows (java实现)
原题题目要求常规解法更聪明的代码原题:You 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 makes a guess,原创 2016-04-16 11:01:24 · 2925 阅读 · 0 评论 -
【LeetCode】345 Reverse Vowels of a String(java)
原题题目要求解法原题Write a function that takes a string as input and reverse only the vowels of a string.Example 1: Given s = “hello”, return “holle”.Example 2: Given s = “leetcode”, return “leotcede”. 题目要原创 2016-05-04 16:15:30 · 3504 阅读 · 1 评论 -
【LeetCode】383 Ransom Note(java)
原题题目要求解法原题Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can原创 2016-08-17 17:35:30 · 6986 阅读 · 0 评论 -
【LeetCode】389 Find the Difference(java)
原题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 added i原创 2016-09-29 23:46:25 · 1133 阅读 · 1 评论 -
【LeetCode】404 Sum of Left Leaves(java实现)
原题Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.题原创 2016-10-20 00:34:27 · 1937 阅读 · 0 评论 -
【LeetCode】387 First Unique Character in a String(java实现)
原题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.s = "loveleetcode",return 2.Note: You may assume t原创 2016-10-20 00:37:41 · 2662 阅读 · 0 评论 -
【LeetCode】400 Nth Digit(java实现)
原题链接https://leetcode.com/problems/nth-digit/原题Find the nthn^th digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …Note: n is positive and will fit within the range of a 32-bit原创 2016-10-24 07:15:21 · 1804 阅读 · 0 评论 -
【LeetCode】401 Binary Watch (java实现)
原题链接https://leetcode.com/problems/binary-watch/原题A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59).Each LED represents a z原创 2016-10-24 07:17:12 · 3068 阅读 · 1 评论 -
【LeetCode】415 Add Strings (java实现)
原题链接https://leetcode.com/problems/add-strings/原题Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is < 5100.Both原创 2016-10-28 07:08:48 · 4894 阅读 · 2 评论 -
【LeetCode】405 Convert a Number to Hexadecimal (java实现)
原题链接https://leetcode.com/problems/convert-a-number-to-hexadecimal/原题Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.Note: 1. Al原创 2016-11-09 23:33:12 · 2388 阅读 · 0 评论 -
【LeetCode】409. Longest Palindrome (java实现)
原题链接https://leetcode.com/problems/longest-palindrome/原题Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.T原创 2016-11-13 07:26:35 · 1126 阅读 · 0 评论 -
【LeetCode】396. Rotate Function(java实现)
原题链接https://leetcode.com/problems/rotate-function/原题Given an array of integers A and let n to be its length. Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define原创 2016-11-18 06:06:05 · 926 阅读 · 0 评论 -
【LeetCode】455. Assign Cookies (java实现)
原题链接https://leetcode.com/problems/assign-cookies/原题Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a g原创 2016-11-29 05:33:35 · 2045 阅读 · 0 评论