Permutation solution for java
Permutation C++ version