You just can set initial value to 1 and flip it's sign every time you meet negative and just return it at the end without conditions
@abisheknair3545 Жыл бұрын
n=1 for i in nums: if i==0: return 0 if i
@sabu45398 ай бұрын
works fine - var arraySign = function(nums) { let product = 1; for(let i = 0; i < nums.length; i++){ product *= nums[i] / 2; if(product == 0) return 0; } return (product > 0) ? 1 : -1 };
@youknownothing_ Жыл бұрын
well i came up with this solution. i had also used kind of the same approach. class Solution { public int arraySign(int[] nums) { int res = 1; for(int n: nums) { if(n == 0) return 0; if(n
@steeve1 Жыл бұрын
literally the exact code I came up with. Finally feel like I am making progress. #feelsgoodman
@NeetCodeIO Жыл бұрын
Nice job 👏
@carlmascarenhas4124 Жыл бұрын
same, i came up with the solution on my own 🤯🤯🥲🥲
@flatmapper Жыл бұрын
Just class Solution: def arraySign(self, nums): result = 1 for num in nums: if num == 0: return 0 if num < 0: result *= -1 return result
@d.h.y Жыл бұрын
The channel we've needed.
@BonerPauler Жыл бұрын
my approach would be why dont we loop a function through each element and determine its sign that calculates number of negatives found in the array the we can deducethe sign of the array...there will a lot of function calls but if we could keep it short i think thatsbetter then multiplying 6:10
@Sibearian_ Жыл бұрын
U could also do a true or false for neg 6:36. So if we encounter a negative number we can negate it.
@ericnl Жыл бұрын
yep, that's what i did too!
@theOPindian Жыл бұрын
leetcode is bugged rn, everyone is getting a 5% solution lol
@jayjanodia9445 Жыл бұрын
Oh wow and here I was thinking it was due to my slow internet conmection
@novascotia2015 Жыл бұрын
class Solution { public int arraySign(int[] nums) { int sign = 1; // Initialize the sign to positive for(int num : nums) { if(num == 0) { return 0; // If the element is 0, the product is 0 } else if(num < 0) { sign ^= 1; // Flip the sign bit if the element is negative } } return sign * 2 - 1; // Convert the sign bit to a sign (-1 or 1) } }
@BurhanAijaz Жыл бұрын
my code: class Solution: def arraySign(self, nums: List[int]) -> int: pro=1 for i in nums: if i==0: return i elif i
@shrit1401 Жыл бұрын
isnt the problem saying to create a function, signFunc()?
@animeshdubey9412 ай бұрын
Thanks a lot.
@arshalakhan567 Жыл бұрын
Hey! Thanks for amazing content. Any idea when hiring will start at FAANG?
@novascotia2015 Жыл бұрын
class Solution { public int arraySign(int[] nums) { int negativeCount = 0; // Initialize the count of negative numbers to 0 for(int num : nums) { if(num == 0) { return 0; // If the element is 0, the product is 0 } else if(num < 0) { negativeCount++; // Increment the count if the element is negative } } if(negativeCount % 2 == 0) { return 1; // Return 1 if the number of negative numbers is even } else { return -1; // Return -1 if the number of negative numbers is odd } } }
@vixguy Жыл бұрын
i think leetcode is having some sort of seizure rn. if you copy and paste one of the top percent solutions it still gives ~5% runtime.
@infinitygod5379 Жыл бұрын
How is may 1 related to question difficulty
@def__init Жыл бұрын
1st question of the month they usually don’t start off crazy hard to scare you off lol
@SAIGOVINDSATISH Жыл бұрын
SIR please upload daily streak question of medium and hard level .You explain concepts in top noch manner .Please help students like us😢