LeetCode
Wendy0719
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
202. Happy Number
Write 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 the number by the sum of the squares of i原创 2016-11-03 17:38:53 · 382 阅读 · 0 评论 -
13. Roman to Integer
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. 解题思路: 罗马数字表示法,基本字符有7个:I,V,X,L,C,D,M,分别表示1,5,10,50,100,500,1000。 在构成数字的时候,有下列规则: 相同的数字连写,所表示的原创 2016-10-29 14:46:09 · 294 阅读 · 0 评论 -
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 times as it原创 2016-10-29 13:37:15 · 306 阅读 · 0 评论 -
405. 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: All letters in hexadecimal (a-f) must be in lowercase. The hexadecimal str原创 2016-10-31 20:51:30 · 342 阅读 · 0 评论 -
231. Power of Two
Given an integer, write a function to determine if it is a power of two.解法一:Language - Java Run Time - 2ms 解题思路:一个整数如果可以表示为2的幂次,就可以表示为100000……;从而这个数减去1就变为011111…… public boolean isPowerOfTwo(int n) {原创 2016-11-01 15:30:38 · 294 阅读 · 0 评论 -
326. Power of Three
Given an integer, write a function to determine if it is a power of three.Follow up: Could you do it without using any loop / recursion? 解法一:Language - Java Run Time - 20ms 解题思路:暴力枚举public boolean原创 2016-11-01 15:55:59 · 439 阅读 · 0 评论 -
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 elements of [1, n] inclusive that do not appear in this array.Could you原创 2017-01-04 20:30:52 · 489 阅读 · 0 评论 -
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 (not diagonally). The grid is completely s原创 2017-01-05 17:05:47 · 383 阅读 · 0 评论 -
455. 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 greed factor gi, which is the minimum size of a cook原创 2017-01-05 19:53:34 · 466 阅读 · 0 评论 -
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, y < 231.Examp原创 2016-12-20 16:22:00 · 525 阅读 · 0 评论 -
206. Reverse Linked List
Reverse a singly linked list. 递归与迭代都是基于控制结构: 迭代用重复结构 递归用选择结构 递归与迭代都涉及重复: 迭代显式使用重复结构 递归通过重复函数调用实现重复 递归与迭代都涉及终止测试: 迭代在循环条件失败时终止 递归在遇到基本情况时终止 使用计数器控制重复的迭代和递归都逐渐到达终止点: 迭代一直修改计数器,直到计数器值使循环条件失败 递归不断产生最初问原创 2016-10-29 16:53:08 · 149 阅读 · 0 评论 -
216. Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Example 1:Input: k = 3, n =原创 2016-10-18 15:17:55 · 382 阅读 · 0 评论 -
404. Sum of Left Leaves
Find the sum of all left leaves in a given binary tree.Example:3 解法一:Language-Java原创 2016-10-13 22:51:25 · 360 阅读 · 0 评论 -
415. Add Strings
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2.Note:1.The length of both num1 and num2 is < 5100. 2.Both num1 and num2 contains only digits 0-9. 3.B原创 2016-10-18 10:50:30 · 161 阅读 · 0 评论 -
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 the multiples of five output “Buzz”. For n原创 2016-10-17 08:57:52 · 414 阅读 · 0 评论 -
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 it should return false if every element is原创 2016-10-14 22:13:31 · 328 阅读 · 0 评论 -
409. 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.This is case sensitive, for example “Aa” is not consider原创 2016-10-14 20:45:10 · 301 阅读 · 0 评论 -
51. N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle.Each solut原创 2016-10-13 14:56:16 · 438 阅读 · 0 评论 -
401. 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 zero or one, with the least significant bit on the原创 2016-10-11 17:31:52 · 460 阅读 · 0 评论 -
137. Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using ex原创 2016-10-10 21:38:10 · 348 阅读 · 0 评论 -
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 non-empty and the majority element always原创 2016-10-09 15:32:22 · 307 阅读 · 0 评论 -
229. Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space. 方法一:Time-O(n) Space-O(1) RunTime-3ms Language-Javapu原创 2016-10-09 15:24:01 · 288 阅读 · 0 评论 -
168. Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 解题思路:逢26进1(A) publ原创 2017-01-13 10:49:32 · 352 阅读 · 0 评论
分享