Clean C# Version


  • 0
    J

    Clean and easy to understand C# version.

    public class Solution {
        public bool IncreasingTriplet(int[] nums) {
            if (nums.Length < 3)
                return false;
            
            int minIndex  = Int32.MinValue;
            int midIndex  = Int32.MinValue;
            
            for (int i = 0; i < nums.Length; i ++)
            {
                int currentNumber = nums[i];
    
                if ( (midIndex != Int32.MinValue) && (currentNumber > nums[midIndex]) )
                    return true;
                    
                if ( (minIndex == Int32.MinValue) || (currentNumber < nums[minIndex]) )
                    minIndex = i;
                
                if (currentNumber > nums[minIndex])
                    midIndex = i;
            }
            
            return false;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.