ขนาดวิดีโอ: 1280 X 720853 X 480640 X 360
แสดงแผงควบคุมโปรแกรมเล่น
เล่นอัตโนมัติ
เล่นใหม่
r = len(num) - 1 res = '' if len(num) == 0: return res while r >=0 and int(num[r])%2 == 0: r -= 1 return res + num[:r+1]
Thanks, finally I did good solution before your video, yeah it's just an easy problem, but I am happy)
my friend likes striver so she doesnot want me to watch your videos.
Can we use heap for the following?
Thank you
def largestOddNumber(self, num): for i in range(len(num)-1,-1,-1): if int(num[i])%2==1: return num[:i+1] return ""
If we start from 0->n(cpp) It shows memory limit exceeded.Why???
Looks like you're out of bounds, try n-1 :)
I thought list slicing was O(N) so why is it not O(N^2)
You only do list slicing once
What? Your answer is in your question.
Yeah in the code there's only one slice, which makes it o(n) :)
it would only be N^2 if you were to do a slicing operation for every iteration of the loop of the input parameter. But in this case, it is only done once
Easy one
A more elegant and pretentious way to check if a number is odd is n & 1.
yes it is lol
Way too easy problem it won't be asked 😂
r = len(num) - 1
res = ''
if len(num) == 0:
return res
while r >=0 and int(num[r])%2 == 0:
r -= 1
return res + num[:r+1]
Thanks, finally I did good solution before your video, yeah it's just an easy problem, but I am happy)
my friend likes striver so she doesnot want me to watch your videos.
Can we use heap for the following?
Thank you
def largestOddNumber(self, num):
for i in range(len(num)-1,-1,-1):
if int(num[i])%2==1:
return num[:i+1]
return ""
If we start from 0->n(cpp)
It shows memory limit exceeded.
Why???
Looks like you're out of bounds, try n-1 :)
I thought list slicing was O(N) so why is it not O(N^2)
You only do list slicing once
What? Your answer is in your question.
Yeah in the code there's only one slice, which makes it o(n) :)
it would only be N^2 if you were to do a slicing operation for every iteration of the loop of the input parameter. But in this case, it is only done once
Easy one
A more elegant and pretentious way to check if a number is odd is n & 1.
yes it is lol
Way too easy problem it won't be asked 😂