![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode Online Judge
文章平均质量分 54
学会知足
这个作者很懒,什么都没留下…
展开
-
Two Sum
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index原创 2015-05-30 16:27:22 · 293 阅读 · 0 评论 -
Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.只有偶数和5(或5的倍数)相乘才会出现0,所以,可以在n之前看看有多少个偶数和5就行了,又发现偶数的数量一定多于5的个数,于是我们只看n原创 2015-08-24 21:46:59 · 279 阅读 · 0 评论 -
House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2015-08-25 16:39:23 · 254 阅读 · 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?这题实际上和费波那契数列很像。上n层楼梯的方法总数s(n原创 2015-08-13 10:42:02 · 350 阅读 · 0 评论 -
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,#,#,15,7}, 3 / \ 9 20原创 2015-08-15 18:05:40 · 235 阅读 · 0 评论 -
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 e转载 2015-08-31 11:54:30 · 289 阅读 · 0 评论 -
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 1 \转载 2015-09-02 17:38:15 · 185 阅读 · 0 评论 -
Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2015-09-09 17:33:20 · 256 阅读 · 0 评论 -
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"]/* use原创 2015-08-20 19:31:17 · 239 阅读 · 0 评论 -
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 ↘原创 2015-08-21 15:10:35 · 232 阅读 · 0 评论 -
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 cont原创 2015-08-21 20:22:47 · 268 阅读 · 0 评论 -
Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()原创 2015-09-13 09:22:39 · 279 阅读 · 0 评论 -
Sort Colors
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the integers原创 2015-09-13 09:42:23 · 309 阅读 · 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-08-22 10:50:46 · 267 阅读 · 0 评论 -
Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. Some hints:Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to stri原创 2015-06-13 11:15:11 · 233 阅读 · 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-12 16:37:21 · 263 阅读 · 0 评论 -
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原创 2015-05-30 09:56:55 · 295 阅读 · 0 评论 -
Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo原创 2015-06-01 09:20:34 · 237 阅读 · 0 评论 -
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)).这道题拿到手里真的是没什么想法。唯一想到能原创 2015-06-02 19:01:15 · 234 阅读 · 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.根据上次题目的想法,弄一个字符指针数组,对s进行扫描的过程中,查找是否与数组里对应的字符串匹配。如果匹配上,即可得到相应数位的值。本身一道简单题,思路很快就有了,但原创 2015-06-25 16:21:04 · 229 阅读 · 0 评论 -
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) and (i, 0). Fin原创 2015-06-23 19:22:03 · 248 阅读 · 0 评论 -
Integer to Roman
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.目前做过的最简单的一道medium的题目,没有数学,没有算法,百度下搞懂罗马数字是怎么回事就行。不过做完后通过看别人的解题,倒是发现“指针数组”这个不错的数据结构,原创 2015-06-24 16:58:28 · 222 阅读 · 0 评论 -
Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.初看到这道题有点被迷惑了,先是看到参数里竟然有char **strs声明的两重指针,不过仔细一想,其实不就是存字符指针的数组么,每个字符指针再指向一个字符串。然后再想了想,若要找到几个字符串的最长的共同前缀,那么这个前缀自然原创 2015-06-26 11:26:23 · 299 阅读 · 0 评论 -
3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:Elements in a triplet (a,b,c原创 2015-06-26 11:29:29 · 325 阅读 · 0 评论 -
LeetCode OJ Summary,Problems 1 - 15
前15题总结:1.Two Sum,使用两种方法:一、快速排序+二分查找;二、哈希表。巩固了二分查找的写法,学习了哈希表的算法,但自己实现的效果不佳。(medium)2.Add Two Numbers,考察的是链表的操作。(easy)3.Longest Substring Without Repeating Characters,哈希表+字符串。(medium)原创 2015-06-27 16:39:11 · 348 阅读 · 0 评论 -
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原创 2015-06-08 11:14:11 · 297 阅读 · 0 评论 -
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.初看到这道题,没什么特别好的想法,就原创 2015-06-08 09:43:05 · 300 阅读 · 0 评论 -
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 codin原创 2015-06-12 17:01:23 · 244 阅读 · 0 评论 -
Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at原创 2015-09-13 10:29:28 · 259 阅读 · 0 评论