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

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 2001. Number of Pairs of Interchangeable Rectangles

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

You are given?n?rectangles represented by a?0-indexed?2D integer array?rectangles, where?rectangles[i] = [widthi, heighti]?denotes the width and height of the?ith?rectangle.

Two rectangles?i?and?j?(i < j) are considered?interchangeable?if they have the?same?width-to-height ratio. More formally, two rectangles are?interchangeable?if?widthi/heighti?== widthj/heightj?(using decimal division, not integer division).

Return?the?number?of pairs of?interchangeable?rectangles in?rectangles.

?

Example 1:

Input: rectangles = [[4,8],[3,6],[10,20],[15,30]]

Output: 6

Explanation: The following are the interchangeable pairs of rectangles by index (0-indexed):

- Rectangle 0 with rectangle 1: 4/8 == 3/6.?

- Rectangle 0 with rectangle 2: 4/8 == 10/20.?

- Rectangle 0 with rectangle 3: 4/8 == 15/30.?

- Rectangle 1 with rectangle 2: 3/6 == 10/20.?

- Rectangle 1 with rectangle 3: 3/6 == 15/30.?

- Rectangle 2 with rectangle 3: 10/20 == 15/30.

Example 2:

Input: rectangles = [[4,5],[7,8]]

Output: 0

Explanation: There are no interchangeable pairs of rectangles.

其實(shí)只要會最大公約數(shù)這個(gè)函數(shù)即可,這樣15 30,跟10 20這一組就是同一類的,然后map存儲每個(gè)的數(shù)量,最后用排列算出來,返回;

?

Constraints:

  • n == rectangles.length

  • 1 <= n <= 105

  • rectangles[i].length == 2

  • 1 <= widthi, heighti?<= 105


Runtime:?123 ms, faster than?8.98%?of?Java?online submissions for?Number of Pairs of Interchangeable Rectangles.

Memory Usage:?93.1 MB, less than?34.28%?of?Java?online submissions for?Number of Pairs of Interchangeable Rectangles.


LeetCode 2001. Number of Pairs of Interchangeable Rectangles的評論 (共 條)

分享到微博請遵守國家法律
清徐县| 独山县| 黄陵县| 广宗县| 乌审旗| 南宫市| 达日县| 永仁县| 枣阳市| 大丰市| 巴彦淖尔市| 肇庆市| 芜湖市| 城市| 大邑县| 建阳市| 天津市| 开远市| 九江县| 云林县| 佛冈县| 镶黄旗| 富顺县| 楚雄市| 奉贤区| 邯郸市| 揭东县| 芮城县| 珠海市| 禄劝| 滕州市| 呈贡县| 锡林郭勒盟| 武胜县| 资源县| 长葛市| 会理县| 台南市| 安阳县| 九龙县| 紫阳县|