Sort by

recency

|

2207 Discussions

|

  • + 0 comments

    def reverseArray(a): # Write your code here r=a[::-1] return r

  • + 0 comments

    Java 7 Solution

    int n = a.size();
    
    for(int i = 0;i<n/2;i++){
    
        int temp = a.get(i);
        a.set(i, a.get(n-i-1));
        a.set((n-i-1), temp);
    
    }
    
  • + 0 comments

    Sometimes i forget some function can turn it much more simple. Here is in Java 8

    Collections.reverse(a);
    return a;
    
  • + 0 comments

    vector reverseArray(vector a) {

       //solution approach 1
     reverse(a.begin(),a.end());
     return a;
    
      //solution appraoch 2
    //  int n=size(a);
    //  vector<int> ans;
    //  for(int i=n-1;i>=0;i--)
    //  {
    //     ans.push_back(a[i]);
    //  }
    //  return ans;
    

    }

  • + 0 comments

    left, right = 0, len(arr) - 1 while left < right: arr[left], arr[right] = arr[right], arr[left] left += 1 right -= 1 return arr