JAVA--------Easy Version To Understand!!!


  • 0
    H
    public static int nthSuperUglyNumber(int n, int[] primes) {
    	if (n <= 0 || primes == null || primes.length == 0)
    		return 0;
    	int len = primes.length;
    	int[] index = new int[len];
    	int[] result = new int[n];
    	result[0] = 1;
    	for (int i = 1; i < n; i++) {
    		int min = Integer.MAX_VALUE;
    		for (int j = 0; j < len; j++) {
    			if (result[index[j]] * primes[j] < min)
    				min = result[index[j]] * primes[j];
    		}
    		result[i] = min;
    		for (int j = 0; j < len; j++) {
    			while (result[index[j]] * primes[j] <= min)
    				index[j]++;
    		}
    	}
    	return result[n - 1];
    }

  • 0
    H

    er.......................


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.