Convert the Temperature — LeetCode 2469 Python Solution

EasyMath
Problem
#2469
Reading time
2 min

The problem

You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius. You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = [kelvin, fahrenheit].

Example

Input
celsius = 36.50
Output
[309.65000,97.70000]
Explanation
Temperature at 36.50 Celsius converted in Kelvin is 309.65 and converted in Fahrenheit is 97.70.

Python solution

Python
class Solution:
    def convertTemperature(self, celsius: float) -> List[float]:
        return [celsius + 273.15, celsius * 1.8 + 32]

Complexity

MeasureComplexity
TimeO(1)
SpaceO(1) auxiliary

Pattern: Math and Number Theory

Find the closed form, the invariant, or the modular identity — and skip the loop entirely. LeetCode 2469. Convert the Temperature is filed here on both counts: the reference solution below belongs to the algorithm family this hub collects, and LeetCode tags it Math.

The math and number theory guide has the Python template for the pattern and the 485 LeetCode problems that use it.

Related problems

Frequently asked questions

How hard is LeetCode 2469. Convert the Temperature?
LeetCode 2469. Convert the Temperature is rated Easy on LeetCode.
What is the time complexity of LeetCode 2469. Convert the Temperature?
The Python solution on this page runs in O(1).
What is the space complexity of LeetCode 2469. Convert the Temperature?
The Python solution on this page uses O(1) auxiliary space.
What topics does LeetCode 2469. Convert the Temperature cover?
LeetCode 2469. Convert the Temperature is tagged Math on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview