[力扣] 算法 1310 (C++)

1310. 子数组异或查询

class Solution {
public:
    vector<int> xorQueries(vector<int>&amp; arr, vector<vector<int>>&amp; queries) {
        for (size_t i = 1, size = arr.size(); i < size; ++i) {
            arr[i] ^= arr[i - 1];
        }
        vector<int> ret(queries.size());
        for (size_t i = 0, size = queries.size(); i < size; ++i) {
            int from = queries[i][0], to = queries[i][1];
            ret[i] = arr[to] ^ (from ? arr[from - 1] : 0);
        }
        return ret;
    }
};

[力扣] 算法 64 (C++)

64. 最小路径和

class Solution {
public:
    int minPathSum(vector<vector<int>>&amp; grid) {
        const int m = grid.size();
        const int n = grid[0].size();
        for (int i = m - 2; i >= 0; --i)
            grid[i][n - 1] += grid[i + 1][n - 1];
        for (int i = n - 2; i >= 0; --i)
            grid[m - 1][i] += grid[m - 1][i + 1];
        for (int i = m - 2; i >= 0; --i)
            for (int j = n - 2; j >= 0; --j)
                 grid[i][j] += min(grid[i + 1][j], grid[i][j + 1]);
        return grid[0][0];
    }
};