Written by
java-style
on
on
줄 서는 방법
줄 서는 방법
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
import java.util. * ; class Solution { static long Factorial( int n) { if (n = = 1 ) return 1 ; return n * Factorial(n - 1 ); } public int [] solution( int n, long k) { int [] answer = new int [n]; ArrayList < Integer > persons = new ArrayList < Integer > (); for ( int i = 1 ;i < = n;i + + ) persons. add (i); k - - ; int pos = 0 ; while (n > 0 ) { long nextNum = Factorial(n) / n; int idx = ( int ) (k / nextNum); answer[pos] = persons.remove(idx); k = k % nextNum; n - - ; pos + + ; } return answer; } } Colored by Color Scripter
from http://zzunsik.tistory.com/240 by ccl(A) rewrite - 2021-11-27 13:01:44