[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/arjunmullick/Interview/master/SquaresSortedArray.java [Back]  [Original]

package com.leetcode;

public class SquaresSortedArray {

    //https://leetcode.com/problems/squares-of-a-sorted-array/
    class Solution {
        public int[] sortedSquares(int[] nums) {
            int n = nums.length;
            int result[] = new int[n];
            int l = 0;
            int r = n-1;
            int counter = n-1;
            while(l=0){
                if(Math.abs(nums[l])>Math.abs(nums[r])){
                    result[counter] = nums[l]*nums[l];
                    l++;
                }else{
                    result[counter] = nums[r]*nums[r];
                    r--;
                }
                counter--;
            }
            return result;

        }
    }
}

Web Proxy Viewer  |  New URL  |  Original Page