Skip to content

AbhishekNayak-24/leetcode-----3397

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

leetcode-----3397

Maximum Number of Distinct Elements After Operations //code in C++ class Solution { public: int maxDistinctElements(vector& nums, int k) { sort(nums.begin(), nums.end()); int cnt = 0, prev = INT_MIN; for (int num : nums) { int curr = min(max(num - k, prev + 1), num + k); if (curr > prev) { cnt++; prev = curr; } } return cnt; } };

About

Maximum Number of Distinct Elements After Operations

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published