0ms solution with explanation | C++
This question was a bit tricky. At first I tried multiplying all the numbers in array to get product and then decide whether it\'s positive or negative or it\'s
This question was a bit tricky. At first I tried multiplying all the numbers in array to get product and then decide whether it\'s positive or negative or it\'s 0. But I got integer overflow error which probably could have been mitigated by $$long$$ or $$long$$ $$long$$ data types, but we have a better idea\uD83D\uDCA1\n\nLet\'s multiply product by 1 if the element is positve instead of the whole number & -1 in case it\'s negative. If it\'s zero, we return 0.\n\nAnd then finally we will return product after this repetitive process. This saved us from the tedioud operation of multiplying the whole number and then storing it.. and as a result we get a much shorter runtime and better space complexity!\n\n``` C++ []\nclass Solution {\npublic:\n    int arraySign(vector<int>& nums) {\n        int product=1;\n        for (int x:nums) {\n            if (x<0) product*=-1;\n            else if (x>0) product*=1;\n            else return 0;\n        }\n        return product;\n    }\n};\n```\n\n## if this explanation helped you please leave a upvote on this solution\n\n## Visit my GitHub: https://github.com/crimsonKn1ght\n\n## Happy coding \uD83D\uDE00
['C++']