国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

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

leetcode2078. Two Furthest Houses With Different Colors

2022-12-30 13:14 作者:您是打尖兒還是住店呢  | 我要投稿

Easy

There are?n?houses evenly lined up on the street, and each house is beautifully painted. You are given a?0-indexed?integer array?colors?of length?n, where?colors[i]?represents the color of the?ith?house.

Return?the?maximum?distance between?two?houses with?different?colors.

The distance between the?ith?and?jth?houses is?abs(i - j), where?abs(x)?is the?absolute value?of?x.

?

Example 1:

Input: colors = [1,1,1,6,1,1,1]Output: 3Explanation: In the above image, color 1 is blue, and color 6 is red. The furthest two houses with different colors are house 0 and house 3. House 0 has color 1, and house 3 has color 6. The distance between them is abs(0 - 3) = 3. Note that houses 3 and 6 can also produce the optimal answer.

Example 2:

Input: colors = [1,8,3,8,3]Output: 4Explanation: In the above image, color 1 is blue, color 8 is yellow, and color 3 is green. The furthest two houses with different colors are house 0 and house 4. House 0 has color 1, and house 4 has color 3. The distance between them is abs(0 - 4) = 4.

Example 3:

Input: colors = [0,1]Output: 1Explanation: The furthest two houses with different colors are house 0 and house 1. House 0 has color 0, and house 1 has color 1. The distance between them is abs(0 - 1) = 1.

一個去遍歷,一個去計算即可,速度肯定不會很快了。


Runtime1 ms

Beats

69.33%

Memory40.5 MB

Beats

70.48%

Click to check the distribution chart


leetcode2078. Two Furthest Houses With Different Colors的評論 (共 條)

分享到微博請遵守國家法律
鄂州市| 上饶县| 全南县| 汶上县| 都昌县| 北安市| 满城县| 德格县| 南郑县| 从化市| 洛宁县| 松江区| 固原市| 娄底市| 海盐县| 柯坪县| 塔城市| 莫力| 甘德县| 青铜峡市| 皋兰县| 万载县| 龙江县| 会理县| 乌拉特前旗| 巴彦淖尔市| 武定县| 宝清县| 蓝山县| 星座| 南昌市| 锦屏县| 康乐县| 翁源县| 朝阳区| 南靖县| 昭平县| 灵武市| 醴陵市| 敦煌市| 白河县|