[leetcode_66]Plus One

大数据加减法 一次AC附上代码,可能不是最优。 class Solution { public: vector<int> plusOne(vector<int> &digits) { // Note: The Solution object is instantiated only once and is reused by each test case. vector<int> ans(digits.size()+1); for(int i = 0……

[leetcode_27]Remove Element

这个题就是个坑!英文一定要学好!题意一定要理解对。 我一开始以为自己求删除之后的长度就可以了!其实不止如此!你还要让A数组前length符合要求。 开始WA 后来一次AC 附上代码: class Solution { public: int removeElement(int A[], int n, int elem) { // Note: The Solution object is instantiated o……

[leetcode_70]Climbing Stairs

爬楼梯,那么一次爬一步,要么一次爬两步。问你有几种爬法? 搜索? 会超时 后来改成迭代: a[n] = a[n-1] + a[n-2] 一次AC class Solution { public: int climbStairs(int n) { // Note: The Solution object is instantiated only once and is reused by each test case. int a1 = 1; int……

[leetcode_136]Single Number

输入一个数组,里面每个元素都有两个,但是有一个元素只有一个。 请在不消耗额外内存空间的情况下,找出那个单一的元素并输出。 此题用异或即可。 不会消耗额外的内存空间。 一次AC,附上代码: class Solution { public: int singleNumber(int A[], int n) { // Note: The Solution object is instantiated……

[leetcode_13]Roman to Integer

这个和上一个题相反。 嘿嘿嘿,比较猥琐的我本来是想用上一个题,打一个3999的表,但是我觉得这样太不厚道了。 于是我选择了好好做题= = 当然上一个题的代码太多的switch 和 if else 所以。。。 我决定改进一下。 附上代码:依然是一次AC class Solution { public: int num; int romanToInt(string s) { ……