🚀

Thanksgiving Sale: Use Coupon Code THANKS25 to Get Extra 25% Off.

00DAYS
:
00HOURS
:
00MINUTES
:
00SECONDS

Leetcode Problem 2229. Check if an Array Is Consecutive

2229. Check if an Array Is Consecutive

Leetcode Solutions

Check Consecutive Sequence Using Set and Range

  1. Convert the input array nums to a set to remove any duplicate values.
  2. Find the minimum value min_val in the set.
  3. Find the maximum value max_val in the set.
  4. Calculate the expected length of the consecutive sequence as max_val - min_val + 1.
  5. Compare the expected length with the actual length of the array. If they are equal, and the size of the set is also equal to the length of the array, return true.
  6. If the expected length does not match the actual length or the set size is not equal to the array length, return false.
UML Thumbnail

Check Consecutive Sequence by Sorting

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...