LeetCode 1552 - Magnetic Force Between Two Balls - Java

Поділитися
Вставка
  • Опубліковано 4 лис 2024

КОМЕНТАРІ • 6

  • @rostyslavmochulskyi159
    @rostyslavmochulskyi159 4 місяці тому +1

    In Java, Arrays.sort() is implemented using a variant of the Quick Sort algorithm which has a space complexity of O(logn) for sorting

    • @Alpha-Code
      @Alpha-Code  4 місяці тому +1

      Gotcha, I think in Python its also not O(1) for sort but most people write it that way.

  • @MehdiKhfifi
    @MehdiKhfifi 4 місяці тому +2

    i don't understand why the left position has to be 1 and not 0?

    • @tzuilee588
      @tzuilee588 4 місяці тому

      it doesn't matter if it's 0 or 1, we are binary searching the gap not the array index

    • @Alpha-Code
      @Alpha-Code  4 місяці тому +1

      It wouldn't matter, but also if you have enough buckets to put the balls in if it was zero you'd put every ball in the same bucket which wouldn't make sense. You can always put the balls in different buckets and the minimum space between buckets is 1.

  • @margin100px
    @margin100px 4 місяці тому

    Cool thumbnail!!