JAVA O(1) solution.... 0ms beats 100% just for fun

  • 0

    because u can at most have 9 numbers in a password we can simply calculate all the numbers beforehand..... looks like cheating, just for fun

    public class Solution {
        public int numberOfPatterns(int m, int n) {
            int[] counts = new int[]{9,56,320,1624,7152,26016,72912,140704,140704};
            int sum=0;
            for (int i=m-1; i<n; i++) sum+=counts[i];
            return sum;

Log in to reply

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