Check the sign - Explained
The first thought probably is just to simulate it by calculating the product of nums and check the sign like what problem statement says. However, We don\'t nee
The first thought probably is just to simulate it by calculating the product of `nums` and check the sign like what problem statement says. However, We don\'t need to do that since we are not interested in the value but the sign. Therefore, we can just check the sign only. If we meet a zero, we can exit early since the final sign must be 0 anyway.\n\n<iframe src="https://leetcode.com/playground/fZuQh2vv/shared" frameBorder="0" width="100%" height="300"></iframe>\n\nYou may notice that when the number is positive, basically it won\'t change the sign. Hence, we can just focus on negative numbers and flip the sign when we meet one. Zero case remain unchanged.\n\n```cpp\nclass Solution {\npublic:\n    int arraySign(vector<int>& nums) {\n        int ans = 1;\n        for (auto x : nums) {\n            if (x == 0) return 0;\n            if (x < 0) ans = -ans;\n        }\n        return ans;\n    }\n};\n```
['Python', 'C++', 'Rust']