↓Skip to main content
  1. LeetCode/

LeetCode 2469: Convert the Temperature

·1 min· ·
LeetCode Easy Math
Wei Yi Chung
Author
Wei Yi Chung
Working at the contributing of open source, distributed systems, and data engineering.
Table of Contents

Meta Data
#

Difficulty: easy First Attempt: 2025-12-17

  • Submissions: Accepted (C++, first try)

Approach
#

The problem gives both conversion formulas; apply them and return [Kelvin, Fahrenheit]. A 1e-5 tolerance is allowed, so floating-point arithmetic is fine.

My Solution
#

I wrote it in C++; here is the equivalent Python:

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

Complexity
#

Time O(1), space O(1).

Mistakes to Avoid
#

  • Kelvin comes first, then Fahrenheit.

Interview Explanation
#

Apply both formulas and return them. With a 1e-5 tolerance, floating-point error does not matter. Time O(1).

Related

LeetCode 3697: Compute Decimal Representation
·1 min
LeetCode Easy Math Array
LeetCode 3697 note: each non-zero digit times its place value is one component; output them from the highest place down
LeetCode 3550: Smallest Index With Digit Sum Equal to Index
·1 min
LeetCode Easy Math Array
LeetCode 3550 note: check indices in increasing order, computing each digit sum; the first match is the answer
LeetCode 1979: Find Greatest Common Divisor of Array
·1 min
LeetCode Easy Math Number-Theory Gcd Array
LeetCode 1979 note: find the minimum and maximum, then take their GCD with Euclid’s algorithm
LeetCode 2235: Add Two Integers
·1 min
LeetCode Easy Math
LeetCode 2235 note: return the sum; the C++ version once failed to compile from a missing semicolon
LeetCode 2413: Smallest Even Multiple
·1 min
LeetCode Easy Math Number-Theory
LeetCode 2413 note: lcm(2, n), which is n when n is even and 2n when odd
LeetCode 1304: Find N Unique Integers Sum up to Zero
·1 min
LeetCode Easy Math Array
LeetCode 1304 note: place 1..n/2 and their negatives so each pair cancels, adding 0 when n is odd