作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 并查集 日期 题目地址:https://leetcode.com/problems/largest-component-size-by-common-factor/description/ 题目描述 Given a non-empty array of unique positive integers A, consider the followin…
You are given an integer array of unique positive integers nums. Consider the following graph: There are nums.length nodes, labeled nums[0] to nums[nums.length - 1], There is an undirected edge between nums[i] and nums[j] if nums[i] and nums[j] share…
Given a non-empty array of unique positive integers A, consider the following graph: There are A.length nodes, labelled A[0] to A[A.length - 1]; There is an edge between A[i] and A[j] if and only if A[i] and A[j] share a common factor greater than 1.…
分析 注意到要求的是最大的连通分量,那么我们可以先打素数表(唯一分解定理),然后对每个要求的数,将他们同分解出的质因子相连(维护一个并查集),然后求出最大的联通分量即可. 这里使用了筛法求素数.初始化内存时利用了一个hack. 代码 var isPrime[100005] bool var pa[100005] int var primeMap=[]int{} func initPrimeNumbers() { isPrime[0]=true for bp:=1;bp<len(isPrime);…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 日期 [LeetCode] https://leetcode.com/problems/remove-duplicates-from-sorted-array/ Total Accepted: 129010 Total Submissions: 384622 Difficulty: Easy 题目描述 Given a sorted array…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 迭代 日期 题目地址:https://leetcode.com/problems/delete-node-in-a-bst/description/ 题目描述 Given a root node reference of a BST and a key, delete the node with the given key in the BST. Re…
[LeetCode]380. Insert Delete GetRandom O(1) 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/insert-delete-getrandom-o1/description/ 题目描述: Design a data structure that supports all following oper…
[LeetCode]718. Maximum Length of Repeated Subarray 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/maximum-length-of-repeated-subarray/description/ 题目描述: Given two integer arr…
[LeetCode]833. Find And Replace in String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/find-and-replace-in-string/description/ 题目描述: To some string S, we will perform some…
[九度OJ]题目1439:Least Common Multiple 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1439 题目描述: The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set…