欢迎光临散文网 会员登陆 & 注册

Leetcode 1512 Number of Good Pairs

2022-02-06 14:28 作者:您是打尖儿还是住店呢  | 我要投稿

Given an array of integers nums, return the number of good pairs.

A pair (i, j) is called good if nums[i] == nums[j] and i < j.

 

Example 1:

Input: nums = [1,2,3,1,1,3]Output: 4Explanation: There are 4 good pairs (0,3), (0,4), (3,4), (2,5) 0-indexed.

Example 2:

Input: nums = [1,1,1,1]Output: 6Explanation: Each pair in the array are good.



Runtime: 1 ms, faster than 81.21% of Java online submissions for Number of Good Pairs.

Memory Usage: 39.7 MB, less than 14.56% of Java online submissions for Number of Good Pairs.

整体表现不太好。只能说一般。

Leetcode 1512 Number of Good Pairs的评论 (共 条)

分享到微博请遵守国家法律