I just don't get it. Why C is slower than Java?
I'm familiar with C/C++, so most of my solution are written in C/C++.\n\nBut why C is so much slower than Java now? Have you changed the judge compiler or somet
I'm familiar with C/C++, so most of my solution are written in C/C++.\n\nBut why C is so much slower than Java now? Have you changed the judge compiler or something backend?\n\nI have three solutions in Java/C/C++ using the same algorithm, and the running time list below:\n\n    Java 94 ms, C 204 ms, C++ 552 ms\n\nC code:\n\n    int nthSuperUglyNumber(int n, int* primes, int primesSize) {\n        if (n <= 0 || primesSize <= 0) return 1;\n    \n        int *index = (int *)calloc(primesSize, sizeof(int));\n        int *nums = (int *)calloc(n, sizeof(int));\n    \n        nums[0] = 1;\n        int storageIndex = 1;\n    \n        while (storageIndex < n) {\n            int min = (1 << 31) - 1;\n            for (int i = 0; i < primesSize; i++) {\n                if (nums[index[i]] * primes[i] < min) {\n                    min = nums[index[i]] * primes[i];\n                }\n            }\n            nums[storageIndex++] = min;\n            for (int i = 0; i < primesSize; i++) {\n                if (nums[index[i]] * primes[i] == min) {\n                    index[i]++;\n                }\n            }\n        }\n\n        int ans = nums[n - 1];\n        free(index);\n        free(nums);\n    \n        return ans;\n    }\n\nJava Code:\n\n    public class Solution {\n        public int nthSuperUglyNumber(int n, int[] primes) {\n            int k = primes.length;\n            if (k == 0 || n <= 0) return 1;\n            \n            int[] index = new int[k];\n            int[] nums = new int[n];\n    \n            nums[0] = 1;\n            \n            int i = 1;\n            while (i < n) {\n                int min = (1 << 31) - 1;\n                for (int j = 0; j < k; j++) {\n                    if (nums[index[j]] * primes[j] < min) {\n                        min = nums[index[j]] * primes[j];\n                    }\n                }\n                nums[i++] = min;\n                for (int j = 0; j < k; j++) {\n                    if (nums[index[j]] * primes[j] == min) {\n                        index[j]++;\n                    }\n                }\n            }\n            \n            return nums[n - 1];\n        }\n    }
['Java']