650. 2 Keys Keyboard
650. 2 Keys Keyboard
Description

Solution
- O(n^2), search from 1 to i-1 to find the smallest operation number for dp[i] 
- O(sqrt(n)), all the operations sequences are like : - CPPPCPPPPCP..., can be divided into groups (CPPP)(CPP)(CP)…. .If we have each group’s length like- g1, g2,g3..., so after first group, there are- g1A’s, after second group- g1 * g2A’s…- We want have - N = g1 * g2 * g3...*gnA’s, if- gican be divided into product of other two numbers, denote as- gi = p * q, so it can be divided into 2 group, first contains 1- Cand p-1- P, second one contains 1- Cand q-1- P. It is easy to prove that after dividing, we need fewer steps.
Code
| 1 | class Solution { | 
| 1 | 
 | 
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.

