
leetcode
csdnlmmmmmm
这个作者很懒,什么都没留下…
展开
-
231. Power of Two
题目Given an integer, write a function to determine if it is a power of two.我的解法public class Solution { public boolean isPowerOfTwo(int n) { if(n == 0) return false;原创 2017-02-27 12:00:49 · 179 阅读 · 0 评论 -
2. Add Two Numbers
题目You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and re原创 2017-02-14 15:57:38 · 164 阅读 · 0 评论 -
219. Contains Duplicate II
题目Given an array of integers and an integer k, find out whether there are two distinct indicesi and j in the array such that nums[i] = nums[j] and theabsolute difference between i and j is at原创 2017-02-22 17:56:20 · 153 阅读 · 0 评论 -
445. Add Two Numbers II
题目You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and原创 2017-02-11 00:56:43 · 271 阅读 · 0 评论 -
242. Valid Anagram
题目Given two strings s and t, write a function to determine ift is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may原创 2017-02-22 16:08:17 · 253 阅读 · 0 评论 -
290. Word Pattern
题目Given a pattern and a stringstr, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter inpattern and a non-empty word instr原创 2017-02-22 14:02:31 · 195 阅读 · 0 评论 -
349. Intersection of Two Arrays
题目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 re原创 2017-02-22 11:17:28 · 162 阅读 · 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 m原创 2017-02-21 22:15:03 · 143 阅读 · 0 评论 -
389. Find the Difference
题目Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling strings and then add one more letter at a random position.Find the letter that原创 2017-02-21 18:19:49 · 171 阅读 · 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原创 2017-02-21 16:44:30 · 150 阅读 · 0 评论 -
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 function twoSum should return indices of the tw原创 2017-03-01 17:15:56 · 206 阅读 · 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 elem原创 2017-02-22 22:43:15 · 154 阅读 · 0 评论 -
205. Isomorphic Strings
题目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 wit原创 2017-02-23 10:11:25 · 171 阅读 · 0 评论 -
204. Count Primes
题目Description:Count the number of prime numbers less than a non-negative number,n.我的解法(超时)public class Solution { public int countPrimes(int n) { int res = 0; if(n - 1原创 2017-02-23 16:37:36 · 144 阅读 · 0 评论 -
258. Add Digits
题目Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like:3 + 8 = 11, 1 + 1 = 2. Since2 has only原创 2017-02-27 11:47:50 · 183 阅读 · 0 评论 -
263. Ugly Number
题目Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, 5. For example, 6, 8 are ugly while14 is not ugly原创 2017-02-27 11:13:10 · 162 阅读 · 0 评论 -
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.我的解法public class So原创 2017-02-27 10:48:32 · 153 阅读 · 0 评论 -
367. Valid Perfect Square
题目Given a positive integer num, write a function which returns True ifnum is a perfect square else False.Note: Do not use any built-in library function such assqrt.Example 1:Input: 16R原创 2017-02-26 18:52:59 · 189 阅读 · 0 评论 -
400. Nth Digit
题目Find the nth 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 signed integer (n 31).Example 1:Inp原创 2017-02-26 15:11:23 · 222 阅读 · 0 评论 -
415. Add Strings
题目Given two non-negative integers num1 andnum2 represented as string, return the sum ofnum1 and num2.Note:The length of both num1 andnum2 is Both num1 andnum2 contains only digits原创 2017-02-24 17:54:09 · 454 阅读 · 0 评论 -
234. Palindrome Linked List
题目Given a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?我的解法/** * Definition for singly-linked list. * public class ListNode {原创 2017-02-16 10:14:02 · 141 阅读 · 0 评论 -
453. Minimum Moves to Equal Array Elements
题目Given a non-empty integer array of sizen, find the minimum number of moves required to make all array elements equal, where a move is incrementingn - 1 elements by 1.Example:Input:[1,2原创 2017-02-24 12:03:43 · 199 阅读 · 0 评论 -
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, and you may not use t原创 2017-02-23 19:56:46 · 95 阅读 · 0 评论 -
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 squ原创 2017-02-23 17:38:39 · 166 阅读 · 0 评论 -
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 you implement it without usi原创 2017-02-21 10:26:59 · 101 阅读 · 0 评论 -
438. Find All Anagrams in a String(不太懂)
题目Given a string s and a non-empty string p, find all the start indices ofp's anagrams in s.Strings consists of lowercase English letters only and the length of both stringss and p will no原创 2017-02-21 00:08:44 · 176 阅读 · 0 评论 -
171. Excel Sheet Column Number
题目Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 .原创 2017-02-27 20:03:02 · 206 阅读 · 0 评论 -
172. Factorial Trailing Zeroes
题目Given an integer n, return the number of trailing zeroes inn!.我的解法(超时)public class Solution { public int twoNum = 0; public int fiveNum = 0; public int trailingZeroes原创 2017-02-27 19:40:11 · 174 阅读 · 0 评论 -
21. Merge Two Sorted Lists
题目Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.我的解法/** * Definition for singly-linked list. *原创 2017-02-17 20:20:05 · 147 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List
题目Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given 1->1->2, return1->2.Given 1->1->2->3->3, return1->2->3.我的解法/** * Defin原创 2017-02-17 12:34:05 · 141 阅读 · 0 评论 -
141. Linked List Cycle
题目Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?答案(两指针法)/** * Definition for singly-linked list. * class ListNode { * i原创 2017-02-16 19:05:55 · 154 阅读 · 0 评论 -
160. Intersection of Two Linked Lists
题目Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘原创 2017-02-16 17:28:37 · 156 阅读 · 0 评论 -
203. Remove Linked List Elements
题目Remove all elements from a linked list of integers that have valueval.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6,val = 6Return: 1 --> 2 --> 3 --> 4 --> 5我的解法/** * Definit原创 2017-02-16 15:38:51 · 153 阅读 · 0 评论 -
206. Reverse Linked List
题目Reverse a singly linked list.我的解法(答案解法之一)/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * }原创 2017-02-16 11:52:10 · 167 阅读 · 0 评论 -
287. Find the Duplicate Number
题目Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate numb原创 2017-02-07 15:01:47 · 200 阅读 · 0 评论 -
414. Third Maximum Number
题目Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).Example 1:Input原创 2017-02-05 23:06:46 · 166 阅读 · 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原创 2017-02-27 21:12:00 · 209 阅读 · 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 andy, calculate the Hamming distance.我的解法publi原创 2017-02-18 16:54:39 · 206 阅读 · 0 评论 -
69. Sqrt(x)
题目Implement int sqrt(int x).Compute and return the square root of x.我的解法public class Solution { public int mySqrt(int x) { int s = 1; int e = x; long mid = 0;原创 2017-02-28 10:29:03 · 244 阅读 · 0 评论 -
447. Number of Boomerangs
题目Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points(i, j, k) such that the distance betweeni and j equals the distance betweeni and k (the order原创 2017-02-20 16:14:50 · 179 阅读 · 0 评论