- Published on
Codesignal - centuryFromYear solution
- Authors
- Name
- Imran Pollob
- Website
- @pollmix
Solution one:
Basic straight forward solution.
def centuryFromYear(year):
if year % 100 == 0:
return year // 100
return (year // 100) + 1
Solution two:
Interesting solution without using else.
def centuryFromYear(year):
return (year + 99) // 100
Solution three:
Same theory as above but using math
library function.
def centuryFromYear(year):
return math.ceil(year / 100)
}
Solution four:
An different math approach.
def centuryFromYear(year):
return (year - 1) / 100 + 1;
}