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.
- Arrays: Left Rotation
- Discussions
Arrays: Left Rotation
Arrays: Left Rotation
Sort by
recency
|
4955 Discussions
|
Please Login in order to post a comment
Listans=new ArrayList(); int n=a.size();
for (int i = 0; i < n; i++) { ans.add(a.get((i+d)%n));
} return ans;
Python slicing 1 line solution:
my java solution
public static List rotLeft(List a, int d) { // Write your code here
public static List rotLeft(List a, int d) { // Write your code here int n= a.size(); List temp = new ArrayList<>(); for(int j=0;jn-1) ? d+j-n : d+j;
temp.add(j,a.get(index)); }
return temp; }