- 博客(53)
- 收藏
- 关注
转载 [leetcode] 260. Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given
2016-07-31 13:30:10 162
转载 [leetcode] 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 using ext
2016-07-31 12:58:56 138
转载 [leetcode] 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 = 5
2016-07-31 12:33:56 113
转载 [leetcode] 8. 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
2016-07-31 07:41:47 146
转载 [leetcode] 165. Compare Version Numbers
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co
2016-07-31 07:19:24 171
转载 [leetcode] 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]. Note:Try to come up as many solutions as y
2016-07-31 06:51:11 148
转载 [leetcode] 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 解法一:之前一
2016-07-31 06:19:34 298
转载 [leetcode] 278. First Bad Version
You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the
2016-07-31 05:59:54 124
转载 [leetcode] 155. 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
2016-07-31 05:37:43 174
转载 [leetcode] 7. Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321click to show spoilers.Have you thought about this?Here are some good questions to ask before c
2016-07-31 04:55:50 161
转载 [leetcode] 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-07-31 04:26:44 159
转载 [leetcode] 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-07-29 13:17:02 151
转载 [leetcode] 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-07-29 12:15:16 125
转载 [leetcode] 204. Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.解法一:大神的解法只能强记了。。。class Solution {public: int countPrimes(int n) { bool isPrimes[n];
2016-07-29 11:59:48 154
转载 [leetcode] 303. Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRan
2016-07-29 11:33:12 148
转载 [leetcode] 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.解法一:class Solution {public: int strStr(string haystack, str
2016-07-29 11:16:37 132
转载 [leetcode] 67. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".解法一:注意的是当a[i] - b[i]+carry ==1的时候,carry可能为1。反正这时候肯定没有进位,重置carry = 0。clas
2016-07-29 11:00:39 249
转载 [leetcode] 14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.解法一:简单粗暴一个个查找。class Solution {public: string longestCommonPrefix(vector& strs) { if(strs.size()
2016-07-29 10:23:28 108
转载 [leetcode] 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 as 001110010
2016-07-28 13:00:35 129
转载 [leetcode] 203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5解法一:思想还是引入一个dummy n
2016-07-28 12:31:34 116
转载 [leetcode] 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?解法一:核心是分别有快慢两个指针,去获取list的中心node的坐标。同时使用一个stack,存储前半段node的数值。这里有一个地方要注意,当
2016-07-28 12:00:08 146
转载 [leetcode] 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-07-28 10:15:46 197
转载 [leetcode] 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-07-28 09:58:46 129
转载 [leetcode] 38. 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
2016-07-28 07:53:48 130
转载 [leetcode] 290. Word Pattern
Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.
2016-07-28 07:24:42 205
转载 [leetcode] 19. 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
2016-07-28 06:43:31 129
转载 [leetcode] 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 ↘
2016-07-27 12:48:21 143
转载 [leetcode] 219. Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j]and the difference between i and j is at most k.解
2016-07-27 12:08:13 149
转载 [leetcode] 257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]解法一:核心思
2016-07-27 11:47:13 165
转载 [leetcode] 223. 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 to
2016-07-27 11:27:08 148
转载 [leetcode] 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 with anot
2016-07-26 12:27:59 161
转载 [leetcode] 225. Implement Stack using Queues
Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet
2016-07-26 12:06:43 160
转载 [leetcode] 299. Bulls and Cows
You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint t
2016-07-26 11:43:07 189
转载 [leetcode] 111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.解法:recursive function. /**
2016-07-25 12:23:00 150
转载 [leetcode] 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-07-25 12:09:45 167
转载 [leetcode] 36. 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
2016-07-25 11:34:46 136
转载 [leetcode] 112. Path Sum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum
2016-07-25 10:38:56 196
转载 [leetcode] 9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.解法一:最naive的解法就是不考虑space的开销。先转成digits,再进一步比较vector。class Solution {public: bool isPalindrome(int x) {
2016-07-25 08:24:59 135
转载 [leetcode] 119. Pascal's Triangle II
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?解法一:这道题的
2016-07-25 07:50:20 145
转载 [leetcode] 102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 2
2016-07-25 07:32:20 128
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人