
Leetcode
__SeanLiu
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Leetcode #1 Two Sum (easy)
问题描述: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原创 2016-09-04 14:33:40 · 265 阅读 · 0 评论 -
Leetcode #344 Reverse String
问题描述:Write a function that takes a string as input and returns the string reversed.思路:(最近做水题做上瘾了)交换数字可以用异或啊啊啊啊啊啊啊啊啊代码:class Solution {public: string reverseString(st原创 2016-09-25 22:13:21 · 166 阅读 · 0 评论 -
Leetcode #241 Different Ways to Add Parentheses
问题描述:Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.原创 2016-10-22 23:37:31 · 201 阅读 · 0 评论 -
Leetcode #327 Count of Range Sum
问题描述:Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive.Range sum S(i, j) is defined as the sum of the elements in nums between indices i原创 2016-10-22 23:48:18 · 353 阅读 · 1 评论 -
Leetcode #240 Search a 2D Matrix II
问题描述:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to rig原创 2016-10-22 23:59:19 · 221 阅读 · 0 评论 -
Leetcode #9 Palindrome Number
问题描述:Determine whether an integer is a palindrome. Do this without extra space.思路:把整数x的右边第一位放在左边第一位、右边第二位放在左边第二位……,然后判断是否相等代码:class Solution {public: bool isPalindrome原创 2016-09-28 20:51:08 · 172 阅读 · 0 评论 -
Leetcode#315 Count of Smaller Numbers After Self
问题描述:You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums原创 2016-10-16 16:29:50 · 231 阅读 · 0 评论 -
Leetcode #215 Kth Largest Element in an Array
问题描述:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k原创 2016-10-16 21:10:33 · 192 阅读 · 0 评论 -
Leetcode #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 subarra原创 2016-10-16 21:18:19 · 218 阅读 · 0 评论 -
Leetcode #357 Count Numbers with Unique Digits
问题描述:Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x n.Example:Given n = 2, return 91. (The answer should be the total numbers in the range of 0 ≤ x < 10原创 2016-09-25 22:38:49 · 202 阅读 · 0 评论 -
Leetcode #343 Integer Break
Leetcode #343 Integer Break原创 2016-10-30 00:16:54 · 199 阅读 · 0 评论 -
Leetcode #377 Combination Sum IV
377. Combination Sum IV原创 2016-10-30 12:59:19 · 224 阅读 · 0 评论 -
Leetcode #96 Unique Binary Search Trees
题目Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2原创 2016-10-30 13:09:02 · 202 阅读 · 0 评论 -
Leetcode #292 Nim Game
题目描述:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone原创 2016-09-25 21:59:20 · 207 阅读 · 0 评论 -
Leetcode #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 h原创 2016-09-25 21:54:57 · 187 阅读 · 0 评论 -
Leetcode #136 Single Number
题目描述:Given an array of integers, every element appears twice except for one. Find that single one.思路:算法很多。最暴力的方法:两重循环遍历一边最容易想到的方法:用一个map来记录出现次数,然后遍历map,找到之出现一次的最高效的方法:利用异或操作,只需要便原创 2016-09-25 21:48:37 · 176 阅读 · 0 评论 -
Leetcode #2 Add Two Numbers(medium)
问题描述: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 i原创 2016-09-04 14:51:21 · 264 阅读 · 0 评论 -
Leetcode #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 i原创 2016-09-04 15:38:57 · 218 阅读 · 0 评论 -
Leetcode #4 Median of Two Sorted Arrays
问题描述:There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:n原创 2016-09-04 19:29:15 · 408 阅读 · 2 评论 -
Leetcode #312 Burst Balloons
问题描述:Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst balloon i y原创 2016-09-18 17:24:15 · 270 阅读 · 0 评论 -
Leetcode #169 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原创 2016-09-18 18:31:16 · 203 阅读 · 0 评论 -
Leetcode #399 Evaluate Divisions
问题描述:Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return the answe原创 2016-10-09 18:57:29 · 241 阅读 · 0 评论 -
Leetcode #11 Container With Most Water
问题描述:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) an原创 2016-10-09 19:00:58 · 187 阅读 · 0 评论 -
Leetcode #14 Longest Common Prefix
问题描述:Write a function to find the longest common prefix string amongst an array of strings.思路:找数组的最长公共前缀。一直遍历数组就好,第i个字符串分别和第0个字符串的第j位作比较,如果不相等,就退出循环。注意特殊情况,数组为空和只有1个元素的情况。原创 2016-10-09 19:13:49 · 193 阅读 · 0 评论 -
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原创 2016-09-25 21:39:02 · 234 阅读 · 0 评论 -
Leetcode #7 Reverse Integer
题目描述:Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321Have you thought about this?Here are some good questions to ask before coding. Bonus poi原创 2016-09-25 21:35:36 · 202 阅读 · 0 评论 -
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原创 2016-09-25 18:27:47 · 202 阅读 · 0 评论 -
Leetcode #104 Maximum Depth of Binary Tree
问题描述:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.思路:递归~代码:原创 2016-09-25 21:43:25 · 188 阅读 · 0 评论 -
Leetcode #5 Longest Palindromic Substring
题目描述:Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.Subscribe原创 2016-09-10 01:26:44 · 285 阅读 · 2 评论