
Leetcode
文章平均质量分 63
littledou2015
真正了不起的程序员对自己程序的每一个字节都了如指掌。
展开
-
55、Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if yo原创 2015-01-26 16:59:42 · 520 阅读 · 0 评论 -
7、Reverse Integer
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321 Mathint reverse(int x) { //此题需要注意两种情况:1、x取最值,特别是最小值;2、反过来的时候需要防止数据溢出,如果溢出需要将原创 2015-01-21 20:08:05 · 337 阅读 · 0 评论 -
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) and (i, 0). Fin原创 2015-01-21 21:23:08 · 395 阅读 · 0 评论 -
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.String方法1:clas原创 2015-01-21 15:42:36 · 307 阅读 · 0 评论 -
1、Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2015-01-21 11:17:37 · 378 阅读 · 0 评论 -
14、Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.Hide Tags Stringstring longestCommonPrefix(vector &strs) { //此题比较简单基本上就是比较字符串的前缀 int len原创 2015-01-22 11:12:20 · 400 阅读 · 0 评论 -
3、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-01-21 15:08:50 · 317 阅读 · 0 评论 -
24、Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y原创 2015-01-23 15:52:46 · 318 阅读 · 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. Linked ListListNode *mergeTwoLists(Lis原创 2015-01-23 14:51:24 · 350 阅读 · 0 评论 -
25、Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is原创 2015-01-23 16:15:29 · 351 阅读 · 0 评论 -
50、Pow(x, n)
Implement pow(x, n).Math Binary Searchdouble pow(double x, int n) { double result = 1; double fact = x; //先把特殊情况排除掉 /* if (n ==原创 2015-01-23 16:47:37 · 638 阅读 · 0 评论 -
27、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-01-23 16:46:29 · 369 阅读 · 0 评论 -
26、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-01-23 16:20:40 · 318 阅读 · 0 评论 -
49、Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.Hide Tags Hash Table String有hash Table标签的似乎总要用到map类型 vector anagrams(ve原创 2015-01-23 17:16:57 · 341 阅读 · 0 评论 -
48、Rotate Image
ou are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?Array void rot原创 2015-01-25 19:48:43 · 434 阅读 · 0 评论 -
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 val原创 2015-01-22 15:12:19 · 447 阅读 · 0 评论 -
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原创 2015-01-21 20:32:52 · 315 阅读 · 0 评论 -
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原创 2015-01-21 19:31:28 · 323 阅读 · 0 评论 -
45、Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i原创 2015-01-26 20:05:27 · 428 阅读 · 0 评论 -
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 element原创 2015-01-27 16:20:32 · 366 阅读 · 0 评论 -
67、Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100". Math Stringstring addBinary(string a, s原创 2015-01-27 17:16:07 · 379 阅读 · 0 评论 -
179、Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve原创 2015-01-27 15:26:50 · 476 阅读 · 0 评论 -
70、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? Dynamic Program原创 2015-01-27 16:45:42 · 348 阅读 · 0 评论 -
34、Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found原创 2015-01-26 22:00:11 · 428 阅读 · 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 ...原创 2015-01-27 15:54:44 · 345 阅读 · 0 评论 -
169、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 string原创 2015-01-27 16:33:42 · 341 阅读 · 0 评论 -
66、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. Array M原创 2015-01-27 17:10:18 · 449 阅读 · 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 array.原创 2015-01-26 21:38:24 · 366 阅读 · 0 评论 -
2、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-01-21 14:43:06 · 339 阅读 · 0 评论 -
9、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-01-21 20:54:26 · 342 阅读 · 0 评论 -
4、Median of Two Sorted Arrays
There are two sorted arrays A and B 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)).Hide Tags Divide and Conquer Ar原创 2015-01-22 14:51:34 · 387 阅读 · 0 评论 -
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 a linked list, remove the nth node from the end of list and return its head.For exam原创 2015-01-22 15:39:27 · 412 阅读 · 0 评论 -
226Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this original tweet by Max Howe原创 2015-06-17 10:39:02 · 489 阅读 · 0 评论