java easy to understand solution


  • 0
    W
    1. you should module 1337 every product
    2. you should bash execute every 10, 100, 100...
    public class Solution {
        public int superPow(int a, int[] b) {
            if (a == 0) {
                return 0;
            }
            int indexb = b.length - 1;
            long base = a;
            long res = 1;
            for (int count = b.length - 1; count >= 0; count--) {
                for (int i = 0; i < b[count]; i++) {
                    res *= base;
                    if (res == 1337) {
                        return 0;
                    }
                    res = res % 1337;
                }
                long tt = base;
                for (int i = 0; i < 9; i++) {
                    base *= tt;
                    if (base == 1337) {
                        return 0;
                    }
                    base = base % 1337;
                }
            }
            return (int)res;
        }
    }

Log in to reply
 

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