6.9 trapRain & rotateImage & plusOne

周四了 要去滑冰好虚= =

  • to do

    1] traptrap

2] Rotate Image

    void mirrorByMid(vector>& matrix) {
        int size = matrix.size();
        for (int i=0; i>& matrix) {
        int size = matrix.size();
        for (int i=0; i>& matrix) {
         mirrorByMid(matrix);
         mirrorByDiag(matrix);
    }

3] Plus One

    vector plusOne(vector& digits) {
        if (digits.empty()) return digits;
        else digits[digits.size()-1] +=1;

        int carry = 0;
        for (int i=digits.size()-1; i>=0; --i) {
            if ( digits[i]+carry > 9 ) {
                digits[i] += carry-10;
                carry = 1;
            } else {
                digits[i] += carry;
                carry = 0;
            }
        }
        if (carry) digits.insert(digits.begin(), carry);
        return digits;
    }

Or better:

    vector plusOne(vector& digits) {
        int carry = 1;
        for (int i=digits.size()-1; i>=0; --i) {
            digits[i] += carry;
            carry = digits[i]/10;
            digits[i] %= 10;
        }
        if (carry) digits.insert(digits.begin(), carry);
        return digits;
    }

你可能感兴趣的:(6.9 trapRain & rotateImage & plusOne)