650. 2 Keys Keyboard

https://leetcode.com/problems/2-keys-keyboard/description/
解题思路:

  1. dp[i] = dp[j] + i/j; when i %j == 0

class Solution {
public int minSteps(int n) {

    int[] dp = new int[n + 1];
    for(int i = 2; i <= n; i++){
        dp[i] = i;
        for (int j = i - 1; j > 1; j--){
            if(i % j == 0){
                dp[i] = dp[j] + i / j;
                break;
            }
        }
    }
    return dp[n];
}

}

你可能感兴趣的:(650. 2 Keys Keyboard)