We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My Java soluton with o(n) time complexity and o(1) space complexity:
publicstaticList<Integer>reverseArray(List<Integer>a){// use a pointer at the start and the end//flip while the left pointer is less than the right pointerintleft=0,right=a.size()-1;while(left<right){intleftVal=a.get(left);intrightVal=a.get(right);a.set(left,rightVal);a.set(right,leftVal);left++;right--;}returna;}
Arrays - DS
You are viewing a single comment's thread. Return to all comments →
My Java soluton with o(n) time complexity and o(1) space complexity: