
leetcode
沐沐余风
这个作者很懒,什么都没留下…
展开
-
[leetcode]: 461. Hamming Distance
1.题目描述 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, y原创 2017-04-30 14:51:45 · 576 阅读 · 0 评论 -
[leetcode]: 557. Reverse Words in a String III
1.题目描述 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.Example 1: Input: “Let’s take LeetCode conte原创 2017-04-30 20:52:57 · 1274 阅读 · 0 评论 -
[leetcode]: 476. Number Complement
1.题目描述 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 guaranteed to fit within the range o原创 2017-04-30 21:27:23 · 326 阅读 · 0 评论 -
[leetcode]: 500. Keyboard Row
1.题目描述 Given a List of words, return the words that can be typed using letters of alphabet on only one row’s of American keyboard Example 1: Input: [“Hello”, “Alaska”, “Dad”, “Peace”] Output: [“Ala原创 2017-04-30 22:39:33 · 371 阅读 · 0 评论 -
[leetcode]: 412. Fizz Buzz
1.题目 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 the multiples of five output “Buzz”.原创 2017-04-30 23:08:20 · 461 阅读 · 0 评论 -
[leetcode]: 344. Reverse String
1.题目 Write a function that takes a string as input and returns the string reversed.Example: Given s = “hello”, return “olleh”. 翻转字符串,很直白的题目 2.代码 python 宝宝终于会偷懒了,深感欣慰啊def reverseString(self, s):原创 2017-04-30 23:16:28 · 399 阅读 · 0 评论 -
[leetcode]: 496. Next Greater Element I
1.题目描述 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 elements in the corresponding places of n原创 2017-05-01 15:08:35 · 391 阅读 · 0 评论 -
[leetcode]: 463. Island Perimeter
1.题目 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 (not diagonally). 翻译:给一个0-1矩阵,1-表示原创 2017-05-01 16:33:40 · 280 阅读 · 0 评论 -
[leetcode]: 292. Nim Game
1.题目描述 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原创 2017-05-01 17:54:10 · 443 阅读 · 0 评论 -
[leetcode]: 485. Max Consecutive Ones
1.题目描述 Given a binary array, find the maximum number of consecutive 1s in this array. 给一个0-1数组,找出最长的连续1的个数例: Input: [1,1,0,1,1,1] Output: 3 2.分析 从左到右遍历数组,对连续的1计数,遇到0则重新开始计数,并更新计数最大值。 3.代码 c++in原创 2017-05-01 18:14:47 · 336 阅读 · 0 评论 -
[leetcode]: 136. Single Number
1.题目描述 Given an array of integers, every element appears twice except for one. Find that single one. 给定一个数组,其中只有一个元素只出现一次,其余均出现两次。找出这个只出现一次的数 2.分析 这个题曾在剑指offer上看过,所以就直接用书上的解法了。 两个相同的数做异或运算,a XOR a原创 2017-05-01 19:34:23 · 372 阅读 · 0 评论 -
[leetcode]: 520. Detect Capital
1.题目 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 following cases holds:All letters in this原创 2017-05-01 21:09:53 · 308 阅读 · 0 评论 -
[leetcode]: 448. Find All Numbers Disappeared in an Array
1.题目描述 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.C原创 2017-05-01 22:16:52 · 334 阅读 · 0 评论 -
[leetcode]: 389. Find the Difference
1.题目描述 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 a原创 2017-05-01 23:35:51 · 407 阅读 · 0 评论 -
[leetcode]: 371. Sum of Two Integers
1.题目描述 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.2.分析 首先想到电路里面加法器的实现: 保留位remain原创 2017-05-02 00:19:49 · 255 阅读 · 0 评论 -
[leetcode]: 258. Add Digits
1.题目描述 Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. 翻译:给定一个非负整数,反复的将它各位上的数相加,直到变为一位数。 例如:38-》3+8=11-》1+1=22.分析 不谈数学技巧,简单while循环即可。3.代码class S原创 2017-05-02 00:28:44 · 357 阅读 · 0 评论 -
[leetcode]: 283. Move Zeroes
1.题目描述 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, 1, 0, 3, 12], after calling yo原创 2017-05-02 11:27:49 · 269 阅读 · 0 评论 -
[leetcode]: 492. Construct the Rectangle
1.题目描述So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L and width W satisfy the following requirements: 1. The area of the rectangul原创 2017-05-02 15:18:20 · 314 阅读 · 0 评论 -
[leetcode]: 167. Two Sum II - Input array is sorted
1.题目描述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. You may assume that each input would have exactly one so原创 2017-05-02 16:03:49 · 304 阅读 · 0 评论 -
[leetcode]: 506. Relative Ranks
1.题目描述Given scores of N athletes, find their relative ranks and the people with the top three highest scores, who will be awarded medals: “Gold Medal”, “Silver Medal” and “Bronze Medal”. Input: [5, 4,原创 2017-05-02 16:45:47 · 1237 阅读 · 0 评论 -
[leetcode]: 455. Assign Cookies
1.题目描述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 greed factor gi, which is the minimum size of原创 2017-05-03 11:39:25 · 402 阅读 · 0 评论 -
[leetcode]: 453. Minimum Moves to Equal Array Elements
1.题目描述Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.Example:Input: [1,2,3]Outp原创 2017-05-03 14:13:36 · 263 阅读 · 0 评论 -
[leetcode]: 349. Intersection of Two Arrays
1.题目描述Given two arrays, write a function to compute their intersection.Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note: Each element in the result must be unique. The result can原创 2017-05-03 15:02:23 · 287 阅读 · 0 评论 -
[leetcode]: 383. Ransom Note
1.题目描述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 be constructed from the magazines原创 2017-05-03 15:36:59 · 364 阅读 · 0 评论 -
[leetcode]: 387. First Unique Character in a String
1.题目描述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”,原创 2017-05-03 16:12:50 · 300 阅读 · 0 评论 -
[leetcode]: 122. Best Time to Buy and Sell Stock II
1.题目描述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 as many transactions as you like (ie, buy原创 2017-05-03 17:03:52 · 264 阅读 · 0 评论 -
[leetcode]: 401. Binary Watch
1.题目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 zero or one, with the least significant bit on原创 2017-05-23 00:03:23 · 298 阅读 · 0 评论 -
[leetcode]: 108. Convert Sorted Array to Binary Search Tree
1.题目Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 给一个有序数组,将其转换为一个高度平衡二叉搜索树2.分析BST的特点是左节点<根结点<右节点 左右子树平衡的话,尽可能两边的元素个数相近。所以每次选择数组中间的数作为根结点,左边元素分配到左子树原创 2017-05-23 00:48:26 · 337 阅读 · 0 评论 -
[leetcode]:171. Excel Sheet Column Number
1.题目描述Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C -> 3...Z -> 26AA -> 27AB -> 28原创 2017-05-03 19:29:52 · 258 阅读 · 0 评论 -
[leetcode]: 168. Excel Sheet Column Title
1.题目描述Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example:1 -> A2 -> B3 -> C...26 -> Z27 -> AA28 -> AB2.分析相当于10进制转26进制 刚好与171. Excel Sheet Co原创 2017-05-03 19:55:07 · 285 阅读 · 0 评论 -
[leetcode]: 35. Search Insert Position
1.题目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.You may assume no duplicates in the array.H原创 2017-05-23 13:34:09 · 287 阅读 · 0 评论 -
[leetcode]: 342. Power of Four
1.题目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. 给一个整数n,判断是否为4的幂2.分析之前已经做过了判断3的幂次方,2的幂次原创 2017-05-23 15:51:00 · 323 阅读 · 0 评论 -
[leetcode]: 217. Contains Duplicate
1.题目描述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 it should return false if every eleme原创 2017-05-04 14:41:48 · 291 阅读 · 0 评论 -
[leetcode]: 504. Base 7
1.题目描述Given an integer, return its base 7 string representation. 给一个十进制整数(-10^7,10^7),转成7进制表示,返回string 例: Input: 100 Output: “202” Input: -7 Output: “-10”2.分析正常进制转换。先判断符号。3.代码c++ string conver原创 2017-05-04 14:57:39 · 479 阅读 · 0 评论 -
[leetcode]: 242. Valid Anagram
1.题目Given two strings s and t, write a function to determine if t is an anagram of s.For example, s = “anagram”, t = “nagaram”, return true. s = “rat”, t = “car”, return false. 翻译:两个字符串s,t,判断t是不是由s中原创 2017-05-04 15:02:29 · 286 阅读 · 0 评论 -
[leetcode]: 13. Roman to Integer
1.题目描述Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 罗马数字转10进制2.分析罗马字母包括: I(1)、V(5)、X(10)、L(50)、C(100)、D(500)和M(1000) 规则: 小数出现在左边表示减法,例原创 2017-05-04 19:48:23 · 327 阅读 · 0 评论 -
[leetcode]: 169. Majority Element
1.题目描述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 a原创 2017-05-04 16:08:27 · 264 阅读 · 0 评论 -
[leetcode]: 66. Plus One
1.题目Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits ar原创 2017-05-24 12:36:56 · 258 阅读 · 0 评论 -
[leetcode]: 26. Remove Duplicates from Sorted Array
1.题目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 space for another array, you must do this in place with原创 2017-05-24 16:16:42 · 235 阅读 · 0 评论 -
[leetcode]: 27. Remove Element
1.题目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 in place with constant memory.The o原创 2017-05-24 16:31:10 · 212 阅读 · 0 评论