摘要:
题意 给一个数组,将0元素移动到数组末尾,要求保持in-place 方法 双指针 代码 class Solution { public: void moveZeroes(vector<int>& nums) { int i = 0, j = 0; int n = nums.size(); for ( 阅读全文
摘要:
题意 给出一个数组, 只存在一个数出现一次, 其余数均出现两次, 求出现一次的数 方法 a ^ a ^ b = b 代码 class Solution { public: int singleNumber(vector<int>& nums) { int res = nums[0], N = num 阅读全文
摘要:
题意 序列含有'{}', '()', '[]', 判断其是否有效 方法 stack 代码 bool isValid(string s) { int N = s.size(); if (N & 1) return false; stack<char> st; for (int i = 0; i < N 阅读全文