
shua
yuccess
这个作者很懒,什么都没留下…
展开
-
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原创 2017-01-03 20:45:38 · 238 阅读 · 0 评论 -
48. Rotate Image 旋转矩阵的通用方法
You 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? class Solution { public: /* * clockwise rotate *原创 2017-01-06 22:42:22 · 439 阅读 · 0 评论 -
41. First Missing Positive
Given an unsorted integer array, find the first missing positive integer. For example, Given [1,2,0] return 3, and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and uses constant原创 2017-01-06 13:18:12 · 202 阅读 · 0 评论 -
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原创 2017-01-06 11:50:56 · 226 阅读 · 0 评论 -
31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible原创 2017-01-06 01:32:28 · 392 阅读 · 0 评论 -
27. Remove Element
Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory.原创 2017-01-05 21:34:38 · 196 阅读 · 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原创 2017-01-05 20:37:08 · 190 阅读 · 0 评论 -
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) { string res; int h = strs.s原创 2017-01-04 12:03:42 · 398 阅读 · 0 评论 -
12. Integer to Roman 13. Roman to Integer 玩转罗马数字
int -> Roman class Solution { public: string intToRoman(int num) { char* c[4][10]={ {"","I","II","III","IV","V","VI","VII","VIII","IX"}, {"","X","XX","XXX","XL","原创 2017-01-04 11:03:03 · 316 阅读 · 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 convertin原创 2017-01-04 08:57:09 · 245 阅读 · 0 评论 -
8. String to Integer (atoi) 对于输入情况的考察
以下几种情况要考虑到1,排除输入空格问题2,确定正负3,排除字母4,处理overflow class Solution { public: int myAtoi(string str) { if (str.empty()) return 0; int i = 0, sign = 1; while (i + 1 < str.size() && isspace(st原创 2017-01-04 07:47:49 · 305 阅读 · 0 评论 -
7. 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原创 2017-01-04 06:48:25 · 291 阅读 · 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 N A P L S I原创 2017-01-04 03:14:54 · 235 阅读 · 0 评论 -
5. Longest Palindromic Substring 暴力 800ms -> dp 97ms -> 回归原始 3ms AC
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: "babad" Output: "bab" Note: "aba" is also a valid answer.原创 2017-01-03 23:54:38 · 250 阅读 · 0 评论 -
54. Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]原创 2017-01-07 01:02:38 · 290 阅读 · 0 评论