无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網 會員登陸 & 注冊

LeetCode 2364. Count Number of Bad Pairs

2023-04-11 11:41 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a?0-indexed?integer array?nums. A pair of indices?(i, j)?is a?bad pair?if?i < j?and?j - i != nums[j] - nums[i].

Return?the total number of?bad pairs?in?nums.

?

Example 1:

Input: nums = [4,1,3,3]

Output: 5

Explanation:?

The pair (0, 1) is a bad pair since 1 - 0 != 1 - 4.?

The pair (0, 2) is a bad pair since 2 - 0 != 3 - 4, 2 != -1.?

The pair (0, 3) is a bad pair since 3 - 0 != 3 - 4, 3 != -1.?

The pair (1, 2) is a bad pair since 2 - 1 != 3 - 1, 1 != 2.?

The pair (2, 3) is a bad pair since 3 - 2 != 3 - 3, 1 != 0.?

There are a total of 5 bad pairs, so we return 5.

Example 2:

Input: nums = [1,2,3,4,5]

Output: 0

Explanation: There are no bad pairs.

?

Constraints:

  • 1 <= nums.length <= 105

  • 1 <= nums[i] <= 109

  • 考慮good pair,也就是i-nums[i]的數(shù)量,然后利用一點點數(shù)學排列組合的知識即可。

Runtime:?50 ms, faster than?34.50%?of?Java?online submissions for?Count Number of Bad Pairs.

Memory Usage:?53.9 MB, less than?89.52%?of?Java?online submissions for?Count Number of Bad Pairs.


LeetCode 2364. Count Number of Bad Pairs的評論 (共 條)

分享到微博請遵守國家法律
卢湾区| 保亭| 普宁市| 白水县| 东乡| 温泉县| 库尔勒市| 轮台县| 岳普湖县| 淮南市| 灵璧县| 西丰县| 迁安市| 湖南省| 佛山市| 双鸭山市| 宜兰市| 镇江市| 专栏| 奉节县| 于都县| 邢台县| 临高县| 宁国市| 竹北市| 霍州市| 雷州市| 巨鹿县| 茂名市| 巴中市| 闻喜县| 宁明县| 彩票| 瑞金市| 永仁县| 乐清市| 海丰县| 桃园市| 喀什市| 通化县| 永安市|