283. 移动零 - 力扣(LeetCode) (leetcode-cn.com)
class Solution {
public:
void moveZeroes(vector<int>& nums) {
int i=0;int j=0;
while(j<nums.size())
{
if(nums[j])
{
nums[i]=nums[j];
i++;
}
j++;
}
for(int k=i;k<j;k++)
nums[k]=0;
}
};
167. 两数之和 II - 输入有序数组 - 力扣(LeetCode) (leetcode-cn.com)
class Solution {
public:
vector<int> twoSum(vector<int>& numbers, int target) {
int left=0;
int right=numbers.size()-1;
int ans[2];
while (left<right)
{
if (numbers[left]+numbers[right]==target)
{ans[0]=left+1;ans[1]=right+1;break;}
else if (numbers[left]+numbers[right]<target)
left++;
else if (numbers[left]+numbers[right]>target)
right--;
}
return vector<int>(ans,ans+2);
}
};