解: 暴力解
固定任何元素在arr1
之後iterate arr2
class Solution(object):
def findTheDistanceValue(self, arr1, arr2, d):
"""
:type arr1: List[int]
:type arr2: List[int]
:type d: int
:rtype: int
"""
count=0
for i in arr1:
s=True
for j in arr2:
if abs(i-j)<=d:
s=False
break
if s:
count+=1
return count
def findTheDistanceValue(self, arr1, arr2, d):
"""
:type arr1: List[int]
:type arr2: List[int]
:type d: int
:rtype: int
"""
count=0
for i in arr1:
s=True
for j in arr2:
if abs(i-j)<=d:
s=False
break
if s:
count+=1
return count
No comments:
Post a Comment