C++ || Easy || 2 Methods || 100 % beat
Intuition\nWe neet to determine the number of postive number , Negative Number , or is there any Zero or not.\n\nMutiply as given in quetion\n-> 1 if x is posit
# Intuition\nWe neet to determine the number of postive number , Negative Number , or is there any Zero or not.\n\nMutiply as given in quetion\n-> 1 if x is positive.\n-> -1 if x is negative.\n-> 0 if x is equal to 0.\n\nIf we have Zero in a array, then product will be zero no matter other Number , because 0*(any number) = 0\n\n# Approach 1\nLet\'s Count the Number of postive Number or Negativer number\n\nif there is any zero in array answer will be 0\nif negative number is odd answer will be -1\nif negative numbers are even answer be 1\nEX \n`-1*-1 = 1`\n`-1*-1*-1 = 1`\n\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n```\nHOPE YOU LIKE IT !! PLEASE VOTE UP...\n```\n\n# code 1\n```\nclass Solution {\npublic:\n    int arraySign(vector<int>& nums) {\n        int pos=0,neg=0;\n        for(int i=0;i<nums.size();i++)\n        {\n            if(nums[i]>0) pos++;\n            else if(nums[i]<0) neg++;\n            else return 0;\n        }\n        if(neg%2==0) return 1;\n        return -1;\n    }\n};\n```\n\n# Approach 2\nLet\'s go dynamically \n\nif we found postive number multiply answer with 1 or leave as it is\n\nif we found 0 directly return 0\n\nif we found negetive multiply with -1\n\nfinally return our answer\n\n```\nHOPE YOU LIKE IT !! PLEASE VOTE UP...\n```\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(1)\n\n# Code 2\n```\nclass Solution {\npublic:\n    int arraySign(vector<int>& nums) {\n        int a = 1;\n        for(auto i : nums){\n            if(i==0) return 0;\n            else if(i>0) a *=1;\n            else a *= -1;\n        }\n        return a;\n    }\n};\n```\n```\nHOPE YOU LIKE IT !! PLEASE VOTE UP...\n```
['C++']