题解 | #牧场奶牛集合区域#
牧场奶牛集合区域
https://www.nowcoder.com/practice/89218acf98234315af1cb3a223935318
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param groups int整型一维数组
# @param n int整型
# @return int整型二维数组
#
class Solution:
def findGatheringAreas(self , groups: List[int], n: int) -> List[List[int]]:
# write code here
i,j,new_groups=0,0,[]
while i<=len(groups)-1 and j<=len(groups)-1:
if i==len(groups)-1 or j==len(groups)-1:
new_groups.append([groups[i],groups[j]])
break
elif groups[j]+1==groups[j+1]:
j+=1
else:
new_groups.append([groups[i],groups[j]])
j+=1
i=j
return new_groups


