Leetcode - Hamming Distance
Leetcode - Consecutive Characters

Leetcode - Perfect Squares

violet posted @ 5 年前 in 算法 with tags Algorithm Golang DP , 418 阅读

https://leetcode.com/problems/perfect-squares/

Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.

Example 1:

Input: n = 12
Output: 3 
Explanation: 12 = 4 + 4 + 4.

Example 2:

Input: n = 13
Output: 2
Explanation: 13 = 4 + 9.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
func numSquares(n int) int {
    if n == 0 {
        return 0
    }
    dp := make([]int, n+1)
    for i := 1; i <= n; i++ {
        dp[i] = math.MaxInt32
    }
    for i := 1; i <= n; i++ {
        for j := 1; j*j <= i; j++ {
            dp[i] = min(dp[i], dp[i-j*j]+1)
        }
    }
    return dp[n]
}
 
func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}
Khajane 2 Login 说:
3 年前

The Khajane 2 of Karnataka state government has over 216 treasuries in one single portal. All the treasures are under one single server which similarly used by the secretariat office of state. As well the monetary details of other applications are all updated from the one single Khajane 2 portal. So through this one portal the financial transactions of the state are all verified in a quick manner. Khajane 2 Login Hence the salary slip generation and disbursement of salary has carried out in Khajane 2. It makes governance easier to check how much amount spent on salaries. Also in similar manner, other funds toward projects and similar kinds of services have managed under Khajane 2.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter