LeetCode
文章平均质量分 63
大大萝卜头cc
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
53. Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1]原创 2017-03-15 21:54:11 · 211 阅读 · 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 elemen原创 2017-03-09 17:25:22 · 187 阅读 · 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 theminutes (0-59).Each LED represents a zero or one, with the least significant bi原创 2017-03-09 16:59:39 · 178 阅读 · 0 评论 -
7. Reverse Integer
public int reverse(int x) { long res=0; while(x!=0) { res=res*10+x%10; x=x/10; } if (res>Integer.MAX_VALUE||res<Integer.MIN_VAL原创 2017-03-05 23:45:58 · 148 阅读 · 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 public class Solution { publ原创 2017-03-05 21:24:49 · 155 阅读 · 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 ... Z -> 26 AA ->原创 2017-03-05 21:23:10 · 167 阅读 · 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 c原创 2017-03-08 21:19:54 · 200 阅读 · 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原创 2017-03-08 21:01:10 · 161 阅读 · 0 评论 -
169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appearsmore than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2017-03-04 16:20:24 · 176 阅读 · 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 constructed from the magazines原创 2017-03-04 15:39:30 · 258 阅读 · 0 评论 -
504. Base 7
Given an integer, return its base 7 string representation.Example 1:Input: 100Output: "202"Example 2:Input: -7Output: "-10"Note: The input will be in range of [-1e7, 1e7]. public c原创 2017-03-04 12:00:22 · 145 阅读 · 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原创 2017-03-04 11:43:01 · 232 阅读 · 0 评论 -
283. Move Zeroes
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 you原创 2017-03-04 11:07:21 · 153 阅读 · 0 评论 -
506. Relative Ranks
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".Example 1:In原创 2017-03-03 22:29:24 · 191 阅读 · 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 mo原创 2017-03-09 17:38:00 · 217 阅读 · 0 评论 -
1. Two Sum
public class Solution { public int[] twoSum(int[] nums, int target) { int len=nums.length; if(nums==null||len==0) return null; int s=0; int[] res=ne原创 2017-03-06 21:19:14 · 142 阅读 · 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? 递归:public class Solution { public static boolean原创 2017-03-10 12:14:54 · 171 阅读 · 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 sin原创 2017-03-14 16:32:59 · 214 阅读 · 0 评论 -
35. Search Insert Position
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 arra原创 2017-03-14 15:36:51 · 168 阅读 · 0 评论 -
190. Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as001110原创 2017-03-14 11:50:26 · 314 阅读 · 0 评论 -
191. Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as theHamming weight).For example, the 32-bit integer ’11' has binary representation 00000原创 2017-03-14 11:48:18 · 164 阅读 · 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 he原创 2017-03-14 11:34:38 · 199 阅读 · 0 评论 -
238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an arrayoutput such that output[i] is equal to the product of all the elements ofnums except nums[i].Solve it without division and in O原创 2017-03-11 15:14:10 · 161 阅读 · 0 评论 -
442. Find All Duplicates in an Array
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appeartwice and others appear once.Find all the elements that appear twice in this array.Could you do it without e原创 2017-03-11 14:24:53 · 174 阅读 · 0 评论 -
338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num原创 2017-03-11 14:06:48 · 163 阅读 · 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. Note:Your algorithm should原创 2017-03-07 18:30:28 · 167 阅读 · 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 withou原创 2017-03-10 18:10:24 · 203 阅读 · 0 评论 -
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; if(Int原创 2017-03-10 15:31:50 · 239 阅读 · 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 squar原创 2017-03-07 11:28:07 · 188 阅读 · 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原创 2017-03-06 22:52:35 · 194 阅读 · 0 评论 -
492. Construct the Rectangle
For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose leng原创 2017-03-03 21:48:58 · 152 阅读 · 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. Since 2 has only原创 2017-02-24 17:08:39 · 148 阅读 · 0 评论 -
476. 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 integer is guaranteed to fit within the rang原创 2017-02-20 15:19:19 · 144 阅读 · 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 { * int val;原创 2017-02-20 15:38:35 · 373 阅读 · 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. * publ原创 2017-02-20 15:37:17 · 153 阅读 · 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, return 1->2.Given 1->1->2->3->3, return 1->2->3. java:/** * Definit原创 2017-02-20 15:33:33 · 256 阅读 · 0 评论 -
206. Reverse Linked List
Reverse a singly linked list.Hint: A linked list can be reversed either iteratively or recursively. Could you implement both?java:/** * Definition for singly-linked list. * public class原创 2017-02-20 15:32:29 · 302 阅读 · 0 评论 -
237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value原创 2017-02-20 15:26:47 · 148 阅读 · 0 评论 -
100. Same Tree
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** * D原创 2017-02-28 22:26:53 · 147 阅读 · 0 评论 -
520. Detect Capital
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原创 2017-02-28 22:02:41 · 154 阅读 · 0 评论
分享