Want to know:
同时记录max和min,然后可以这样避免负数 int min = nums[0], max = nums[0];int res = nums[0];for (int i = 1; i < nums.length; i++) {if (nums[i] >= 0) {max = Math.max(nums[i], max * nums[i]);min = Math.min(nums[i], min * nums[i]);} else if (nums[i] < 0) {int oldMax = max;max = Math.max(nums[i], min * nums[i]);min = Math.min(nums[i], oldMax * nums[i]);}res = Math.max(res, max);}return res;
Get a detailed, AI-powered explanation for this question and thousands more on StudyFetch.
Get the Answer for FreeHow StudyFetch Helps You Master This Topic
AI-Powered Answers
Get instant, detailed explanations powered by AI that understands your course material.
Deep Understanding
Go beyond surface-level answers with step-by-step breakdowns and examples.
Personalized Learning
Spark.E adapts to your learning style and helps you connect ideas.
Practice & Test
Turn any question into flashcards, quizzes, and practice tests to solidify your knowledge.