Similar RGB Color


  • 0

    Click here to see the full article post


  • 0

    For Brute Force, do we really need 3 loop?

    To get a * a+b * b+c * c smallest, we can make sure a, b, c itself is the smallest.

    So we can lower the complexity from O(16 * 16 * 16) to O(3 * 16).

    Yes, both are O(1). But the latter one looks better.


  • 0
    S

    What is the logic behind this step in second approach:

    (q % 17 > 8 ? 1 : 0)


  • 0
    A

    q = q / 17 + (q % 17 > 8 ? 1 : 0); want to know how this method work to find out which color component will be used? Thanks


  • 0

    @Alfred_Mao @shubham75
    We want to round q / 17.0 [the float] to the nearest 17 [integer]. If q%17 > 8, then we will round up (answer q // 17 + 1); otherwise we round down (answer q // 17), where // is integer division.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.