Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class test {
- public static void main(String[] args) {
- int arr[] = {8, 5, 11, 4, 6};
- System.out.println(moves(arr));
- }
- public static int moves(int arr[]) {
- int moves = 0;
- int left = 0;
- int right = arr.length - 1;
- for (int i = 0; i < arr.length; i++) {
- while (arr[left] % 2 == 0) {
- left++;
- }
- while (arr[right] % 2 == 1) {
- right--;
- }
- if (left < right) {
- int temp = arr[left];
- arr[left] = arr[right];
- arr[right] = temp;
- moves++;
- }
- }
- return moves;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement