bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 165. Compare Version Numbers

165. Compare Version Numbers

Leetcode Solutions

Approach: Split + Parse, Two Pass

  1. Split both version1 and version2 by the dot character into two arrays nums1 and nums2.
  2. Iterate over the longest array and compare the integer values of the corresponding elements from nums1 and nums2.
  3. If one array ends before the other, assume the remaining elements are '0'.
  4. If an element from nums1 is greater than the corresponding element from nums2, return 1.
  5. If an element from nums1 is less than the corresponding element from nums2, return -1.
  6. If all compared elements are equal, return 0.
UML Thumbnail

Approach: Two Pointers, One Pass

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...