leetcode
Mr丶Caleb
中国科学技术大学在读研究生
展开
-
Leetcode 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.The order原创 2016-12-05 20:02:36 · 561 阅读 · 0 评论 -
Leetcode 80. Remove Duplicates from Sorted Array II(从已排序数组中移除重复元素)
跟26一样 给定一个已排序的数组,删除重复的元素,这样每个元素最多只出现两次,并且返回新的数组长度。不允许为另一个数组使用额外的空间,你必须就地以常量空间执行这个操作。例如, 给定[1,1,1,2,2,3]你的函数应该返回length = 5, 其数组元素分别是1,1,2,2,3。它不关心你离开后的新长度。class Solution { public: int removeDuplic原创 2016-12-05 19:25:03 · 338 阅读 · 0 评论 -
LeetCode 26 Remove Duplicates from Sorted Array(从已排序数组中移除重复元素)
给定一个已排序的数组,删除重复的元素,这样每个元素只出现一次,并且返回新的数组长度。不允许为另一个数组使用额外的空间,你必须就地以常量空间执行这个操作。例如, 给定输入数组为 [1,1,2]你的函数应该返回length = 2, 其前两个元素分别是1和2。它不关心你离开后的新长度。class Solution { public: int removeDuplicates(vector<in原创 2016-12-04 19:41:06 · 295 阅读 · 0 评论 -
7. Reverse Integer
题目中明确提出了要考虑越界的问题,首先记录一下各个数据类型的取值范围: int: 4byte = 32 bit 有符号signed范围:2^31-1 ~ -2^31即:2147483647 ~ -2147483648无符号unsigned范围:2^32-1 ~ 0即:4294967295 ~ 0unsigned int 0~4294967295 int -2147483648~21原创 2016-09-26 17:35:27 · 284 阅读 · 0 评论 -
6. ZigZag Conversion
这题在通常面试中不太常见,难点是找规律,可以发现周期T = 2*numRows - 2;如果不是首行和末尾行的时候,会把T - 2*numRows的索引插入到字符串中。然后再把T索引的字符插入字符串,交替进行,程序中用了一个flag来完成交替。class Solution { public: string convert(string s, int numRows) { in原创 2016-09-25 16:49:29 · 259 阅读 · 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. 最长回文子字符串:1.思路一:暴力枚举,以每个元素原创 2016-09-24 17:25:26 · 392 阅读 · 0 评论 -
4. Median of Two Sorted Arrays
https://leetcode.com/problems/median-of-two-sorted-arrays/class Solution { public: double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { nums1.insert(nums1.end(), nums2.be原创 2016-09-20 15:50:35 · 233 阅读 · 0 评论 -
3. Longest Substring Without Repeating Characters
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原创 2016-09-19 19:55:14 · 229 阅读 · 0 评论