an Android 3x3 key lock screen and two integers m and n, where 1 ≤ m ≤ n ≤ 9, count the total number of unlock patterns of the Android lock screen, which consist of minimum of m keys and maximum n keys. • څ㟬Ұݸ3*3 త android ղᙘ໘ɼ࠶څ㟬ၷݸᏐࣈm᪑n, 1 ≤ m ≤ n ≤ 9 ɻٻ༻࠷গm ݸᴍɼ࠷ଟ n ݸᴍతղํ ๏తᏐɻ
If the line connecting two consecutive keys in the pattern passes through any other keys, the other keys must have previously selected in the pattern. No jumps through non selected key is allowed. Ռၷݸᴍதؒៃա㠥Ұݸᴍɼಹݸᴍඞਢ೭લቮៃ աɼՌᔒաతबෆ߹๏ɻ • The order of keys used matters. ᴍతॱংੋॏཁత
-> Int { setupPrerequests() var sum = 0 for k in m...n { for start in 0..<9 { sum += numPatterns(lastNum: start, currentDotNum: 1, targetDotNum: k) } } return sum } }
-> Int { setupPrerequests() var sum = 0 for k in m...n { sum += 4 * numPatterns(lastNum: 0, currentDotNum: 1, targetDotNum: k) sum += 4 * numPatterns(lastNum: 1, currentDotNum: 1, targetDotNum: k) sum += numPatterns(lastNum: 4, currentDotNum: 1, targetDotNum: k) } return sum } } ࣌ؒෳᯑ: O(n) ۭؒෳᯑ: O(1) Runtime: 382 ms