# Reverse an array ## Assignment Write a method that returns an array in reverse order: `[1, 2, 3, 4]` →`[4, 3, 2, 1]` ```java public static int[] reverseArray(int[] toReverse) { int[] reversed = new int[toReverse.length]; for(int i = 0; i < toReverse.length; i++) { reversed[i] = toReverse[toReverse.length-1-i]; } return reversed; } ``` Zeitkomplexität O(n) Platzkomplexität O(n) ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up