Sign of An Array - Leetcode 1822 - Python

  Рет қаралды 6,865

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 28
@DeathSugar
@DeathSugar Жыл бұрын
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
@abisheknair3545 Жыл бұрын
n=1 for i in nums: if i==0: return 0 if i
@sabu4539
@sabu4539 8 ай бұрын
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_
@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
@steeve1 Жыл бұрын
literally the exact code I came up with. Finally feel like I am making progress. #feelsgoodman
@NeetCodeIO
@NeetCodeIO Жыл бұрын
Nice job 👏
@carlmascarenhas4124
@carlmascarenhas4124 Жыл бұрын
same, i came up with the solution on my own 🤯🤯🥲🥲
@flatmapper
@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
@d.h.y Жыл бұрын
The channel we've needed.
@BonerPauler
@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_
@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
@ericnl Жыл бұрын
yep, that's what i did too!
@theOPindian
@theOPindian Жыл бұрын
leetcode is bugged rn, everyone is getting a 5% solution lol
@jayjanodia9445
@jayjanodia9445 Жыл бұрын
Oh wow and here I was thinking it was due to my slow internet conmection
@novascotia2015
@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
@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
@shrit1401 Жыл бұрын
isnt the problem saying to create a function, signFunc()?
@animeshdubey941
@animeshdubey941 2 ай бұрын
Thanks a lot.
@arshalakhan567
@arshalakhan567 Жыл бұрын
Hey! Thanks for amazing content. Any idea when hiring will start at FAANG?
@novascotia2015
@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
@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
@infinitygod5379 Жыл бұрын
How is may 1 related to question difficulty
@def__init
@def__init Жыл бұрын
1st question of the month they usually don’t start off crazy hard to scare you off lol
@SAIGOVINDSATISH
@SAIGOVINDSATISH Жыл бұрын
SIR please upload daily streak question of medium and hard level .You explain concepts in top noch manner .Please help students like us😢
@Rob-147
@Rob-147 Жыл бұрын
Legend
@flatmapper
@flatmapper Жыл бұрын
One of the easiest problems
@kirillzlobin7135
@kirillzlobin7135 6 ай бұрын
Amazing
@krishnachoudhary4924
@krishnachoudhary4924 Жыл бұрын
The leetcode link is for another problem though.
Find the Difference of Two Arrays - Leetcode 2215 - Python
7:34
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
String Matching in an Array - Leetcode 1408 - Python
8:01
NeetCodeIO
Рет қаралды 798
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 190 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 760 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 157 М.
Product of Array Except Self - Leetcode 238 - Python
11:54
NeetCode
Рет қаралды 675 М.
Minimum Penalty for a Shop - Leetcode 2483 - Python
14:58
NeetCodeIO
Рет қаралды 10 М.
15 Python Libraries You Should Know About
14:54
ArjanCodes
Рет қаралды 410 М.
Programming Is NOT Enough | Add these 7 skills…
13:19
Travis Media
Рет қаралды 423 М.
The Ultimate Tier Programming Tier List | Prime Reacts
26:57
ThePrimeTime
Рет қаралды 518 М.
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 158 МЛН