Detailed analysis and explanation for 3 approach in Python with time comparison
Simple approach but contains explanation to why I wrote what I wrote!\nClearly, you cannot multiply each element and then return the sign of the product. This i
## Simple approach but contains explanation to why I wrote what I wrote!\nClearly, you cannot multiply each element and then return the sign of the product. This is not feasible as we will be storing large size of data.\n\n`Check the execution time for each approach in Python at the end of 3 python approaches`\n# Code in Python: Approach 1\n\n1. Given that we have to `return 0` when we find a \'0\', simply put in a condition in the loop for this.\n2. Initialize `sign` to 1 and if you find a **neg**ative **num**ber, **flip the sign**\n3. Return the `sign` at the end.\n``` Python_Approach_1 []\nclass Solution:\n    def arraySign(self, nums: List[int]) -> int:\n        sign = 1\n\n        for i in nums:\n\n            if i == 0:\n                return 0\n\n            if i < 0:\n                sign = -sign\n        \n        return sign\n```\n# Code in Python: Approach 2\n1. Return 0, if you find 0 in the list.\n2. Initiliaze `sign=1`.\n3. For each element, set `sign *= element//abs(element)`\n\n``` Python_Approach_2 []\nclass Solution:\n    def arraySign(self, nums: List[int]) -> int:\n        sign = 1\n\n        for i in nums:\n\n            if i == 0:\n                return 0\n\n            sign *= i // abs(i)\n        \n        return sign\n```\n# Code in Python: Approach 3\n1. Return 0, if you find 0 in the list.\n2. Initiliaze `countOfNegatives=0`.\n3. For each **neg**ative **ele**ment, set `countOfNegatives += 1`.\n4. After the loop, **return 1** if `countOfNegatives % 2 == 0`. This means that there are even number of negatives.\n**(-1)<sup>2*n</sup> = 1**\n5. Else, return -1\n**(-1)<sup>2*n+1</sup> = -1**\n\n``` Python_Approach_3 []\nclass Solution:\n    def arraySign(self, nums: List[int]) -> int:\n        countOfNegatives = 0\n\n        for i in nums:\n\n            if i == 0:\n                return 0\n\n            if i < 0:\n                countOfNegatives += 1\n        \n        return 1 if countOfNegatives % 2 == 0 else -1\n```\n<br>\n\n# Comparing Python execution time using timeit (in ms)\n```ExecutionTime_Approach1 []\n>>>timeit.timeit(\'-19<0\', number = 10**8) \n    + timeit.timeit(\'-(-19)\', number = 10**8)\n2.5612723330050358\n```\n\n```ExecutionTime_Approach2 []\n>>>timeit.timeit(\'1 * (-19)//abs(-19)\', number = 10**8)\n3.7137523339988547\n>>>timeit.timeit(\'-1 * (-19)//abs(-19)\', number = 10**8)\n3.7235794579974026\n```\n\n```ExecutionTime_Approach3 []\n>>>timeit.timeit(\'-19<0\', number = 10**8) \n    + timeit.timeit(\'1+1\', number = 10**8)\n    + timeit.timeit(\'2 % 2 == 0\', number = 10**8)\n4.421872499995516\n```\n---\n\n# Code in C\n1. Use an **int** **var**iable for `sign` and initialize to 1.\n2. When you find a negative number, **flip the sign**.\n3. At the end, return the `sign`.\n``` C []\nint arraySign(int* nums, int numsSize){\n\n# Initialize sign to 1\nint sign = 1;\n\nfor(int i =0; i<numsSize; i++){\n\n    if(nums[i] == 0)\n        # If you encounter zero, the entire product will be zero\n        return 0;\n\n    if (nums[i] < 0)\n        # If number is negative, flip the sign\n        sign = -sign;\n}\n\nreturn sign;\n}\n```\n\n### Please consider upvoting if you liked it or comment if you have a better alternative! Thank you!
['Array', 'Math', 'C', 'Number Theory', 'Python3']