2024-06-20发表2025-01-15更新LeetCode每日一题几秒读完 (大约95个字)0次访问2748. 美丽下标对的数目最长特殊序列 II 难度: easy 原始链接: https://leetcode.cn/problems/number-of-beautiful-pairs 标签: 哈希 解法一: 哈希go12345678910111213141516171819202122232425func countBeautifulPairs(nums []int) int { ans := 0 countArr := make([]int, 10) for _, num := range nums { num1 := num % 10 for j := 1; j < 10; j++ { if countArr[j] > 0 && gcd(j, num1) == 1 { ans += countArr[j] } } num2 := num for num2 >= 10 { num2 /= 10 } countArr[num2]++ } return ans}func gcd(num1, num2 int) int { if num2 == 0 { return num1 } return gcd(num2, num1%num2)} 2748. 美丽下标对的数目https://wuhunyu.top/leetcode/2024/06/number-of-beautiful-pairs/index.html作者wuhunyu发布于2024-06-20更新于2025-01-15许可协议#哈希