}; 下面这种解法基于费马平方和定理 Fermat's theorem on sums of two squares的一般推广形式:当某个数字的 4k+3 型的质数因子的个数均为偶数时,其可以拆分为两个平方数之和(each prime that is congruent to 3 mod 4 appears with an even exponent in the prime facto
费马平方和定理 Fermat's theorem on sums of two squares的一般推广形式:当某个数字的 4k+3 型的质数因子的个数均为偶数时,其可以拆分为两个平方数之和(each prime that is congruent to 3 mod 4 appears with an even exponent in the prime factorization of the number)。那么我们只要统计其质数因子的个...
public boolean judgeSquareSum(int c) { for(int i=0;i<=c;i++) { for(int j=0;j<=c;j++) { if(i*i+j*j==c) { return true; } } } return false; } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 方法二: 从0 和sqrt(n)两端分别查找 public boolean judgeSquareSum2(int c) { in...
package leetcode // 解法一 最快的解是 DP + 单调栈 func sumSubarrayMins(A []int) int { stack, dp, res, mod := []int{}, make([]int, len(A)+1), 0, 1000000007 stack = append(stack, -1) for i := 0; i < len(A); i++ { for stack[len(stack)-1] != -1 && A[i]...
977. 有序数组的平方 Squares of a Sorted Array 力扣 LeetCode 题解 04:43 2181. 合并零之间的节点 Merge Nodes in Between Zeros 力扣 LeetCode 题解 05:30 3177. 求出最长好子序列 II Find the Maximum Length of a Good Subsequence II 力扣LeetCode题解 09:16 3176. 求出最长好子序列 I Find...
0977-squares-of-a-sorted-array.go 0981-time-based-key-value-store.go 0989-add-to-array-form-of-integer.go 0994-rotting-oranges.go 1029-two-city-scheduling.go 1046-last-stone-weight.go 1071-greatest-common-divisor-of-strings.go 1137-n-th-tribonacci-number.go 1143-Longest-Common-Subsequence...
0977-squares-of-a-sorted-array.cpp 0981-time-based-key-value-store.cpp 0983-minimum-cost-for-tickets.cpp 0994-rotting-oranges.cpp 1024-video-stitching.cpp 1046-Last-Stone-Weight.cpp 1046-last-stone-weight.cpp 1071-greatest-common-divisor-of-strings.cpp 1091-shortest-path-in-binary-matrix.c...
本题建议和leetcode 698. Partition to K Equal Sum Subsets K个子集 + 深度优先搜索DFS 一起学习 建议和这一道题leetcode 518. Coin Change 2 动态规划DP 、leetcode 279. Perfect Squares 类似背包问题 + 很简单的动态规划DP解决 、leetcode 377. Combination Sum IV 组合之和 + DP动态规划 + DFS深度优...
LeetCode 698. Partition to K Equal Sum Subsets Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal. Example 1: Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4 Output: True...
[LeetCode] 698. Partition to K Equal Sum Subsets Problem Given an array of integers nums and a positive integer k, find whether it's possible to divide this array into k non-empty subsets whose sums are all equal. Example 1: Input: nums = [4, 3, 2, 3, 5, 2, 1], k = 4...