Java Skew Binary solution