Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Leopoldo Hernandez
Without a stack. Arguably same space complexity. One less iteration needed

Leopoldo Hernandez

Feb 7, 2024

class Solution2: def decimalToBinary(self, num): # 2 Approach two is to simply create a string with the remainders on our first loop new_num = '' while num > 0: new_num = str(num % 2) + new_num num = num // 2 return new_num

0

0

Comments
Comments
L
Lee 2 years ago

On this page