I have the following snippet of code:
public static int digPow(int n, int p) {
int powCounter = p;
int sum = 0;
char[] digits = (""+n).toCharArray();
for (char digit : digits) {
sum += Math.pow(Character.getNumericValue(digit), powCounter);
powCounter++;
}
if (sum % n == 0) return sum / n;
else return -1;
}
I don't understand how to define the time complexity, because, even though I have a loop, it seems to me that it's not just O(n). Or it is?