LeetCode解题报告
文章平均质量分 59
cs-leo
这个作者很懒,什么都没留下…
展开
-
Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the tota原创 2015-06-17 11:28:36 · 342 阅读 · 0 评论 -
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原创 2015-06-07 16:15:13 · 239 阅读 · 0 评论 -
Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length.原创 2015-06-07 16:33:56 · 293 阅读 · 0 评论 -
Plus One
Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. 给你一个非负数的整形数组,加原创 2015-06-09 14:06:32 · 320 阅读 · 0 评论 -
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. 考察对有序链表的使用,归并。 package leetcode; public原创 2015-06-09 12:09:08 · 316 阅读 · 0 评论 -
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原创 2015-06-09 12:58:04 · 215 阅读 · 0 评论 -
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 Credits原创 2015-06-10 10:53:30 · 265 阅读 · 0 评论 -
Add Binary
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". wa了很多次,进位考虑的不仔细。 package leetcode; public class AddBinary { pub原创 2015-06-09 21:53:14 · 362 阅读 · 0 评论 -
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? 即求菲波拉契数列,第一次 publ原创 2015-06-10 08:58:40 · 307 阅读 · 0 评论 -
Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the原创 2015-06-10 13:52:58 · 239 阅读 · 0 评论 -
Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get原创 2015-06-12 19:50:10 · 216 阅读 · 0 评论 -
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原创 2015-06-16 07:52:41 · 275 阅读 · 0 评论 -
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 with anot原创 2015-06-16 08:56:22 · 305 阅读 · 0 评论 -
Implement strStr()
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. Update (2014-11-02): The signature of the function had been updat原创 2015-06-08 08:24:07 · 296 阅读 · 0 评论 -
Count and Say
The 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原创 2015-06-08 09:43:00 · 252 阅读 · 0 评论 -
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原创 2015-06-16 22:24:55 · 311 阅读 · 0 评论 -
Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character '.'. A partially fille原创 2015-06-16 07:18:47 · 239 阅读 · 0 评论 -
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原创 2015-06-19 10:29:17 · 317 阅读 · 0 评论 -
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原创 2015-06-18 16:50:41 · 286 阅读 · 0 评论 -
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]. Note: Try to come up as many solutions as yo原创 2015-06-19 09:18:04 · 296 阅读 · 0 评论 -
ZigZagConversion
P A H N A P L S I I G Y I R And then read line by line: "PAHNAPLSIIGYIR" Write the code that will take a string and make this conversion given a number of rows: string convert(stri原创 2015-06-05 11:34:02 · 297 阅读 · 0 评论 -
Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting th原创 2015-06-06 07:23:01 · 258 阅读 · 0 评论 -
String to Integer (atoi)
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2015-06-06 08:15:57 · 581 阅读 · 0 评论 -
Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 click to show spoilers. Have you thought about this? Here are some good questions to ask before c原创 2015-06-06 09:14:42 · 266 阅读 · 0 评论 -
Longest Common Prefix
Longest Common Prefix Total Accepted: 49556 Total Submissions: 192089My Submissions Question Solution Write a function to find the longest common prefix string amongst an array of原创 2015-06-06 13:29:45 · 274 阅读 · 0 评论 -
Roman to Integer
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 了解规则,进行运算。 基本字符 I V X L C D M 相原创 2015-06-06 13:01:42 · 273 阅读 · 0 评论 -
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原创 2015-06-07 15:47:25 · 239 阅读 · 0 评论 -
Count Primes
最主要的是对素数的倍数进行处理,时间复杂度大大降低; for (int j = i * i; j < n; j += i) { isPrime[j] = false; } Description: Count the number of prime numbers less than a non-negative number, n.原创 2015-06-16 09:07:40 · 421 阅读 · 0 评论