Skip to content

Instantly share code, notes, and snippets.

@jwasinger
Last active June 23, 2020 04:02
Show Gist options
  • Save jwasinger/8d08281ed90b81da16968a452a12d3a5 to your computer and use it in GitHub Desktop.
Save jwasinger/8d08281ed90b81da16968a452a12d3a5 to your computer and use it in GitHub Desktop.
for i in [0..vec.len]:
vec[i] = vec[i] * vec[i]
return sorted(vec)
@ashirk94
Copy link

This is what I got so far:

class Solution {
public:
vector sortedSquares(vector& A) {
for (unsigned int i = 0; i < A.size(); i++)
A[i] = A[i] * A[i];

    int temp = 0;
    
    for (unsigned int i = 0; i < A.size() - 1; i++)
    {    
        for (unsigned int j = 0; j < A.size()-i-1; j++)  
            if (A[j] > A[j+1])  
            {
                int temp = A[j];
                A[j] = A[j+1];
                A[j+1] = temp;
            }

    }
    return A;
}

};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment