Tap to unmute

Leetcode - Integer to Roman (Python)

  Рет қаралды 5,960

Timothy H Chang

Timothy H Chang

Күн бұрын

Пікірлер: 9
@israellopez9340
@israellopez9340 2 жыл бұрын
hahaha loved the last quote "do not trust me, i know nothing" 😂 after solving the problem
@bradendavis1073
@bradendavis1073 2 жыл бұрын
when i run the program it says "def intToRoman(self, num: int) -> str:" has a syntax error. any idea why?
@janmichaelaustria620
@janmichaelaustria620 3 жыл бұрын
I think all solutions to this are O(1) since the set of all roman numerals is constant - fixed rather. That's the argument I was seeing on discussion boards. class Solution(object): def intToRoman(self, num): """ :type num: int :rtype: str """ numbers = [1,4,5,9,10,40,50,90,100,400,500,900,1000] letters = ['I','IV','V','IX','X','XL','L','XC','C','CD', 'D','CM','M'] output = "" start = len(numbers)-1 while num > 0: while num // numbers[start] >= 1: output += letters[start] num -= numbers[start] start -= 1 return output
@toniomz1205
@toniomz1205 3 жыл бұрын
Hi Tim I have a coming interview with FB, what do you recommend me to study? Which algo? This is for DE not SWE. Thanks and congrats on your channel
@timc3406
@timc3406 3 жыл бұрын
Best of luck! Here's a resource I thought was helpful towardsdatascience.com/the-facebook-data-engineer-interview-345235afaac0
@VladBurlutsky
@VladBurlutsky 3 жыл бұрын
I did somewhat similar: def intToRoman(self, num: int) -> str: ans=[] roman = {1000:'M',900:'CM', 500:'D', 400:'CD', 100:'C', 90:'XC', 50:'L', 40:'XL', 10:'X', 9:'IX', 5:'V', 4:'IV', 1:'I'} for k, v in roman.items(): ans.append(num//k*v) num%=k return "".join(ans) also I would argue that time is O(1) as there is a finite set of Roman numerals therefore Space is also constant
@cs_peter_lorenz
@cs_peter_lorenz 3 ай бұрын
thanks for sharing
@CEOofTheHood
@CEOofTheHood 3 жыл бұрын
Hey Tim, isn't this cheating tho. I couldn't figure out a way to solve it without keeping all the possible Roman numerals in the lookup either. My binary search solution. I think it is faster for the case if the number is 1001. class Solution: def intToRoman(self, num: int) -> str: values = [1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900, 1000] numerals = ['I', 'IV', 'V', 'IX', 'X', 'XL', 'L', 'XC', 'C', 'CD', 'D', 'CM', 'M'] number="" idx=-1 while num!=0: if num >= values[idx]: number+=numerals[idx] num-=values[idx] else: idx=bisect.bisect(values,num,hi=idx)-1 return number
@sinnyman2157
@sinnyman2157 3 жыл бұрын
Hey, Great video, +sub and like, for noob for me it would be great if u explained the details a bit more while writing the code.
Leetcode - Coin Change (Python)
6:49
Timothy H Chang
Рет қаралды 13 М.
Integer to Roman - Leetcode 12 - Python
9:43
NeetCode
Рет қаралды 82 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Python Programming Practice: LeetCode #13 -- Roman to Integer
17:12
Roman Numerals Explained With Many Examples!
14:18
The Organic Chemistry Tutor
Рет қаралды 463 М.
Leetcode - Roman to Integer (Python)
5:18
Timothy H Chang
Рет қаралды 25 М.
Let's code a HANGMAN GAME in Python! 🕺
25:07
Bro Code
Рет қаралды 24 М.
Как наука победила религию
17:02
Writing Code That Runs FAST on a GPU
15:32
Low Level
Рет қаралды 578 М.
The Black Box Method: How to Learn Hard Concepts Quickly
14:09
Colin Galen
Рет қаралды 1,1 МЛН
Roman to Integer - Leetcode 13 - Arrays & Strings (Python)
6:15
So You've Been Rejected from FAANG
5:56
Timothy H Chang
Рет қаралды 9 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН