977. Squares of a Sorted Array

#include <iostream>
#include <algorithm>
#include "vector"
using namespace std;


vector<int> sortedSquares(vector<int>& A)
{
	vector<int>::iterator it;
	for (it = A.begin(); it != A.end(); it++)
	{
		(*it) *= *it;
	}
	sort(A.begin(), A.end());
	return A;
}

int main()
{
	vector<int>A;
	A.push_back(-7);
	A.push_back(-3);
	A.push_back(2);
	A.push_back(3);
	A.push_back(11);
	sortedSquares(A);
	vector<int>::iterator it;
	for (it = A.begin(); it != A.end(); it++)
	{
		cout << *it<<" ";
	}

	system("pause");
	return 0;
}

 

上一篇:Leetcode刷题2-977. 有序数组的平方(C++)


下一篇:JavaScript : 基本的处理事件