1、只出现一次的数字(异或)
class Solution
{
public:int singleNumber(vector<int>& nums){int val = 0;for (auto e : nums){val ^= e; return val;}}
};
2、杨辉三角形
#include <iostream>
#include <vector>
using namespace std;class Solution
{
public:static vector<vector<int>> generate(int numRows){vector<vector<int>> vv;vv.resize(numRows);for (size_t i = 0; i < vv.size(); ++i){vv[i].resize(i + 1, 0);vv[i].front() = vv[i].back() = 1; }for (size_t i = 0; i < vv.size(); ++i){for (size_t j = 0; j < vv[i].size(); ++j){if (vv[i][j] == 0){vv[i][j] = vv[i - 1][j] + vv[i - 1][j - 1];}}}return vv;}
};int main()
{Solution::generate(5);return 0;
}