Largest Odd Number in String - Leetcode 1903 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ก.พ. 2025

ความคิดเห็น • 17

  • @akshayiithyd
    @akshayiithyd ปีที่แล้ว +3

    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]

  • @34535fff
    @34535fff ปีที่แล้ว +2

    Thanks, finally I did good solution before your video, yeah it's just an easy problem, but I am happy)

  • @srilekhaig2442
    @srilekhaig2442 2 วันที่ผ่านมา +1

    my friend likes striver so she doesnot want me to watch your videos.

  • @thebosslevelstudios995
    @thebosslevelstudios995 ปีที่แล้ว +1

    Can we use heap for the following?

  • @shaiksoofi3741
    @shaiksoofi3741 7 หลายเดือนก่อน

    Thank you

  • @ajith4249
    @ajith4249 ปีที่แล้ว

    def largestOddNumber(self, num):
    for i in range(len(num)-1,-1,-1):
    if int(num[i])%2==1:
    return num[:i+1]
    return ""

  • @amanchavhan4159
    @amanchavhan4159 ปีที่แล้ว +1

    If we start from 0->n(cpp)
    It shows memory limit exceeded.
    Why???

    • @Vancha112
      @Vancha112 ปีที่แล้ว

      Looks like you're out of bounds, try n-1 :)

  • @chrischika7026
    @chrischika7026 ปีที่แล้ว

    I thought list slicing was O(N) so why is it not O(N^2)

    • @jessezigi2419
      @jessezigi2419 ปีที่แล้ว +1

      You only do list slicing once

    • @azikkii
      @azikkii ปีที่แล้ว

      What? Your answer is in your question.

    • @Vancha112
      @Vancha112 ปีที่แล้ว

      Yeah in the code there's only one slice, which makes it o(n) :)

    • @leeroymlg4692
      @leeroymlg4692 ปีที่แล้ว

      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

  • @dk4882
    @dk4882 ปีที่แล้ว

    Easy one

  • @RexSacriticulus
    @RexSacriticulus ปีที่แล้ว +2

    A more elegant and pretentious way to check if a number is odd is n & 1.

  • @winwin2369
    @winwin2369 ปีที่แล้ว

    Way too easy problem it won't be asked 😂