Back to course home
0% completed
Vote For New Content
I dont understand the logic behind using the math.in and the integer.max_value. ...
Bryan Pena
Aug 18, 2022
I dont understand the logic behind using the math.in and the integer.max_value. can someone please explain how this works
0
0
Comments
Comments
B
Bryan Pena3 years ago
*math.min
T
Tyler Moson3 years ago
Integer.MAX_VALUE is used because we're looking for the smallest subarray, you start off with the largest number that can be represented as an integer to have something that will always be larger than any actual solution. That way, the moment you have a window where the...
T
Tyler Moson3 years ago
Math.min() is used because it's a simpler way to write: if (minLength > windowEnd - windowStart + 1){ minLength = windowEnd - windowStart + 1 } Using Math.min(), you only do the math for the comparison number once, and that number is returned if it's smaller.