作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 回溯法 日期 题目地址:https://leetcode.com/problems/number-of-squareful-arrays/ 题目描述 Given an array A of non-negative integers, the array is squareful if for every pair of adjacent eleme…
给定一个长度小于 12 的数组 要求排列方式的种数 使得相邻和为完全平方 不考虑数学结构 将问题转化为 一笔画问题 和为完全平方代表 之间存在通路 回溯法 N^N 记忆化搜索 NN 2^N 判断是否是完全平方 int(x0.5+0.5)2 ==x 对于函数使用 functools.lru_cache(None) 关闭lru功能 记忆化搜索的简洁形式 最后因为这个不区分相同的数字(需要除掉相应的阶乘…
题目如下: Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square. Return the number of permutations of A that are squareful.  Two permutations A1 and A2 differ if and only i…
Given an array A of non-negative integers, the array is squareful if for every pair of adjacent elements, their sum is a perfect square. Return the number of permutations of A that are squareful.  Two permutations A1 and A2 differ if and only if ther…
Median of Two Sorted Arrays There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).SOLTION 1: 1. 我们借用findKthNumber的思想.先实现findKthNumber,如果是偶数个,…
题目要求 Given two arrays, write a function to compute their intersection. 题目分析及思路 给定两个数组,要求得到它们之中共同拥有的元素列表(列表中元素是唯一的).可以将所给数组转成集合,利用集合的交集的概念,最后将结果转成列表即可. python代码 class Solution: def intersection(self, nums1: List[int], nums2: List[int]) -> List[int]: n…
[LeetCode]792. Number of Matching Subsequences 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/number-of-matching-subsequences/description/ 题目描述: Given string S and a dictionary of words words,…
[LeetCode]299. Bulls and Cows 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/bulls-and-cows/description/ 题目描述: You are playing the following Bulls and Cows game with your friend: You write down…
[LeetCode]518. Coin Change 2 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/coin-change-2/description/ 题目描述: You are given coins of different denominations and a total amount of money. Write a…
[LeetCode]474. Ones and Zeroes 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/ones-and-zeroes/description/ 题目描述: n the computer world, use restricted resource you have to generate maximum benef…