Python 3 lines very simple code
Code\n\nclass Solution:\n    def maxSelectedElements(self, nums: List[int]) -> int:\n        data={}\n        for i in sorted(nums): data[i],data[i+1]=max(data.
# Code\n```\nclass Solution:\n    def maxSelectedElements(self, nums: List[int]) -> int:\n        data={}\n        for i in sorted(nums): data[i],data[i+1]=max(data.get(i,0),data.get(i-1,0)+1),max(data.get(i+1,0),data.get(i,0)+1)\n        return max(data.values())\n```
['Hash Table', 'Sorting', 'Python3']