2018.5.27 记录自己用C++开始刷LeetCode

从零开始,从简单开始,刷LeetCode题库

1.两数之和

class Solution {
public:
    vector twoSum(vector& nums, int target) {
       vector result;
        for(int i=0;i            for(int j=i+1;j                if(nums[i]+nums[j]==target){
                    result.push_back(i);
                    result.push_back(j);
                    break;
                }
      }
    }
        return result;
    }
};


7反转整数

class Solution {
public:
    int reverse(int x) {
        const int int_max=0x7fffffff;
        const int int_min=0x80000000;
        long long result=0;
        if(x){
            result=result*10+(x%10);
            x=x/10;
        }
        if(resultint_max){
            result=0;
}
        return result;
}

};


9回文数

class Solution {
public:
    bool isPalindrome(int x) {
        int input=x;
        int result=0;
        if(x<0){
            return false;
        }else{
            while(input){
                result=result*10+input%10;
                input=input/10;
            }
            if(result==x){
                return true;
            }else{
                return false;
            }
        }
    }

};



你可能感兴趣的:(2018.5.27 记录自己用C++开始刷LeetCode)