Leetcode - Reordered Power of 2 (Python)

preview_player
Показать описание
March 2021 Leetcode Challenge
Leetcode - Reordered Power of 2 #869
Difficulty: Medium
Рекомендации по теме
Комментарии
Автор

Nice solution. I found that you can optimize this from "faster than 20% of submissions" to "faster than 73.8% of submissions" by putting a stop in the while loop for when you are considering powers of 2 with more digits than are in our inputted int (i.e. if we throw in 3, we don't need to consider if we can reconstruct 3 into 64).

(before the while loop)
num_input_int_digits = sum(c.values())

(in while loop)

elif num_input_int_digits < sum(d.values()):
return False

sidasdf
Автор

Thanks for the explanation, What is the time and space complexity of the algorithm? We go through the while loop log(N) times. But I'm not sure about time/space complexity at each round.

zahraaskarzadeh
Автор

I dont understand, isnt c, just a single digit? and d aswell?, so youre only comparing each of those digits at a time, no? please explain anyone

MadChrisp