Sort a array, [W B W B B W W B ] === [W W W W B B B B ]
Anonymous
I failed, but finally I got the answer: void sort(String[] arr){ int start = 0; int end = arr.length -1; while(start < end){ while(arr[start].equals("W")){ start++; } while(arr[end].equals("B")){ end--; } if(start < end){ arr[start] = "W"; arr[end] = "B"; } start++; end--; } }
Check out your Company Bowl for anonymous work chats.