Java | 2ms | 99.33% faster
\n\nclass Solution {\n    public int maximumProduct(int[] nums) {\n        if(nums.length==3)\n            return nums[0]*nums[1]*nums[2];\n        int max1st=I
![image](https://assets.leetcode.com/users/images/9e06bc71-6bb9-497f-9e46-ee5d5fca5ca5_1623251680.127314.png)\n```\nclass Solution {\n    public int maximumProduct(int[] nums) {\n        if(nums.length==3)\n            return nums[0]*nums[1]*nums[2];\n        int max1st=Integer.MIN_VALUE,max2nd=Integer.MIN_VALUE,max3rd=Integer.MIN_VALUE,min1 = Integer.MAX_VALUE,min2 = Integer.MAX_VALUE;\n        for(int num:nums){\n            if(max1st<=num){\n                max3rd=max2nd;\n                max2nd=max1st;\n                max1st=num; \n            }\n            else if(max2nd<=num)\n            {\n                 max3rd=max2nd;\n                 max2nd=num; \n            }\n            else if(max3rd<=num)            \n                 max3rd=num; \n            if (num<min1) {\n                min2 = min1;\n                min1 = num;\n            }\n            else if (num<min2) {\n                min2 = num;\n            }\n        }\n        return Math.max(min1*min2*max1st,max1st*max2nd*max3rd);\n    }\n}\n\n\n\n```
['Java']