
Leetcode
文章平均质量分 64
SHURamos
这个作者很懒,什么都没留下…
展开
-
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原创 2016-09-18 16:53:09 · 299 阅读 · 0 评论 -
383. Ransom Note
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 constru原创 2016-09-19 09:12:50 · 288 阅读 · 0 评论 -
171. Excel Sheet Column Number
public class Solution { public int titleToNumber(String s) { int len=s.length(); int sum=0; int x=1; len--; while(len>=0){ sum+=(s.charAt(len)-6原创 2016-09-19 11:40:43 · 279 阅读 · 0 评论 -
242. Valid Anagram
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.Note:You may a原创 2016-09-19 16:28:29 · 260 阅读 · 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 include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly sinc原创 2016-09-20 19:28:41 · 258 阅读 · 0 评论 -
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 without原创 2016-09-20 20:18:34 · 317 阅读 · 0 评论 -
345. Reverse Vowels of a String
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".Note原创 2016-09-21 11:19:54 · 318 阅读 · 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:Input原创 2016-10-10 17:26:32 · 262 阅读 · 0 评论 -
231. Power of Two
Given an integer, write a function to determine if it is a power of two.My solution:public class Solution { public boolean isPowerOfTwo(int n) { if(n<1) return false;原创 2016-09-21 18:13:05 · 253 阅读 · 0 评论 -
387. First Unique Character in a String
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:原创 2016-09-21 20:14:06 · 269 阅读 · 0 评论 -
397. Integer Replacement
397. Integer Replacement QuestionEditorial Solution My SubmissionsTotal Accepted: 7473Total Submissions: 26784Difficulty: MediumContributors: AdminGiven a positive原创 2016-10-13 15:35:19 · 324 阅读 · 0 评论 -
415. Add Strings
415. Add Strings QuestionEditorial Solution My SubmissionsTotal Accepted: 4311Total Submissions: 9894Difficulty: EasyContributors: AdminGiven two non-negative numbe原创 2016-10-13 16:04:42 · 299 阅读 · 0 评论 -
67. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".public class Solution { public String addBinary(String a, String b) {原创 2016-09-28 13:39:39 · 253 阅读 · 0 评论 -
38. Count and Say
he count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as "原创 2016-09-28 16:44:53 · 253 阅读 · 0 评论 -
28. Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.public class Solution { public int strStr(String haystack, Str原创 2016-10-14 20:56:25 · 206 阅读 · 0 评论 -
58. Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2016-09-29 22:07:47 · 228 阅读 · 0 评论 -
14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.My solution:public class Solution { public String longestCommonPrefix(String[] strs) { StringB原创 2016-10-18 15:55:32 · 221 阅读 · 0 评论 -
125. Valid Palindrome
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a原创 2016-10-18 20:31:16 · 245 阅读 · 0 评论 -
50. Pow(x, n)
Implement pow(x, n).My solution:public class Solution { public double myPow(double x, int n) { long l=(long)n; if(l>=0) return pow(x,l); else原创 2016-10-19 09:34:58 · 415 阅读 · 0 评论 -
392. Is Subsequence
Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) strin原创 2016-11-21 14:17:52 · 229 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b",原创 2016-11-21 16:55:48 · 274 阅读 · 0 评论 -
70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?My Solutionpublic class原创 2016-11-22 16:30:02 · 209 阅读 · 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 squares原创 2016-11-23 17:26:26 · 194 阅读 · 0 评论 -
151. Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".My Solution:public class Solution { public String reverseWords原创 2016-11-23 20:41:00 · 338 阅读 · 0 评论 -
441. Arranging Coins
You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins.Given n, find the total number of full staircase rows that can be formed.原创 2016-11-24 13:25:06 · 228 阅读 · 0 评论 -
187. Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri原创 2016-11-24 20:10:27 · 243 阅读 · 0 评论 -
2. Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link原创 2016-11-25 19:04:48 · 225 阅读 · 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.Example:Given nums =原创 2016-11-25 20:40:09 · 222 阅读 · 0 评论 -
6. ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I原创 2016-11-25 22:23:29 · 249 阅读 · 0 评论 -
Maximum Gap
Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements原创 2016-12-16 16:10:17 · 246 阅读 · 0 评论 -
20. Valid Parentheses
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 va原创 2016-12-21 16:53:53 · 252 阅读 · 0 评论 -
189. Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].public class Solution { public void rotat原创 2016-12-22 21:37:02 · 210 阅读 · 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) { boolean[] hash=new boolean[n]; int原创 2016-12-23 10:20:44 · 268 阅读 · 0 评论 -
374. Guess Number Higher or Lower
We are playing the Guess Game. The game is as follows:I pick a number from 1 to n. You have to guess which number I picked.Every time you guess wrong, I'll tell you whether the number is h原创 2016-12-27 14:27:44 · 275 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
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原创 2016-12-28 14:59:27 · 254 阅读 · 0 评论 -
80. Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first fi原创 2016-12-28 16:27:25 · 239 阅读 · 0 评论 -
83. Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.1.public class Soluti原创 2016-12-28 19:02:06 · 262 阅读 · 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 <原创 2016-12-29 15:03:17 · 405 阅读 · 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.Coul原创 2016-12-29 16:43:04 · 201 阅读 · 0 评论 -
88. Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional原创 2017-01-07 20:31:10 · 233 阅读 · 0 评论