c++
明明77
这个作者很懒,什么都没留下…
展开
-
[leetcode]1.Two Sum
题目链接:https://leetcode.com/problems/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 su转载 2017-12-13 18:57:42 · 136 阅读 · 0 评论 -
[leetcode] 20. Valid Parentheses
题目链接:https://leetcode.com/problems/valid-parentheses/Given a string containing just the characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.The brackets must close in the转载 2017-12-17 11:09:44 · 153 阅读 · 0 评论 -
[leetcode] 14. Longest Common Prefix[leetcode] 14. Longest Common Prefix
题目链接:https://leetcode.com/problems/longest-common-prefix/Write a function to find the longest common prefix string amongst an array of strings.思路每次子串长度加1,直到子串不相等即是最大公共前缀class Solution { public: str转载 2017-12-17 10:56:55 · 130 阅读 · 0 评论 -
[leetcode] 13. Roman to Integer
题目链接:https://leetcode.com/problems/roman-to-integer/Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路罗马数字总共有七个 即I(1)、V(5)、X(10)、L(50)、C(100)、转载 2017-12-17 10:48:20 · 128 阅读 · 0 评论 -
[leetcode] 9. Palindrome Number
题目链接:https://leetcode.com/problems/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转载 2017-12-17 10:38:45 · 175 阅读 · 0 评论 -
[leetcode] 7. Reverse Integer
题目链接:https://leetcode.com/problems/reverse-integer/Reverse digits of an integer.Example1: x = 123, return 321 Example2: x = -123, return -321思路注意溢出情况处理class Solution { public: int reverse(int x) {转载 2017-12-17 10:22:50 · 108 阅读 · 0 评论 -
[leetcode] 6. ZigZag Conversion
题目链接:https://leetcode.com/problems/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 fon转载 2017-12-17 10:07:14 · 106 阅读 · 0 评论 -
[leetcode] 4. Median of Two Sorted Arrays
题目链接: https://leetcode.com/problems/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 tim转载 2017-12-15 09:48:13 · 109 阅读 · 0 评论 -
[Leetcode]2.Add Two Numbers
题目链接:https://leetcode.com/problems/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转载 2017-12-14 13:38:22 · 131 阅读 · 0 评论 -
面试-剑指offer-数组中出现次数超过一半的数字
题目数组中有一个数字出现的次数超过数组长度的一般,请找出这个数字。思路 解法一:基于Partition函数的O(n)算法 数组中有一个数字出现的次数超过了数组长度的一般。如果把这个数组排序,那么排序之后位于数组中间的数字一定就是那个出现次数超过数组长度一半的数字。也就是说,这个数字就是统计学上的中位数,即长度为n的数组中第n/2大的数字。我么有成熟的O(n)的算法得到数组中任意第k大的数字。 快速排转载 2017-12-14 21:58:21 · 156 阅读 · 0 评论 -
面试--求数组,左边的数都小于等于它,右边的数都大于等于它
题目在一个 int 数组里查找这样的数,它大于等于左侧所有数,小于等于右侧所有数。直观想法是用两个数组 a、b。a[i]、b[i]分别保存从前到 i 的最大的数和从后到 i 的最小的数,一个解答:这需要两次遍历,然后再遍历一次原数组,将所有 data[i]>=a[i-1]&&data[i]<=b[i]的 data[i]找出即可。给出这个解答后,面试官有要求只能用一个辅助数组,且要求少遍历一次。转载 2017-12-14 19:04:44 · 2662 阅读 · 0 评论 -
[leetcode] 27. Remove Element
题目链接:https://leetcode.com/problems/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 matt转载 2017-12-17 15:21:59 · 126 阅读 · 0 评论