Easy
Last updated 4 years ago
Was this helpful?
Given an integer array arr, count element x such that x + 1 is also in arr. If there're duplicates in arr, count them separately.
arr
x
x + 1
class Solution: def countElements(self, arr: List[int]) -> int: count = 0 for a in arr: if a+1 in arr: count += 1 return count