Skip to content

Commit a7ae81c

Browse files
committed
solutions: 2469 - Convert the Temperature (Easy)
1 parent 975996e commit a7ae81c

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
description: 'Author: @wingkwong | https://leetcode.com/problems/convert-the-temperature/'
3+
tags: [Math]
4+
---
5+
6+
# 2469 - Convert the Temperature (Easy)
7+
8+
## Problem Link
9+
10+
https://leetcode.com/problems/convert-the-temperature/
11+
12+
## Problem Statement
13+
14+
You are given a non-negative floating point number rounded to two decimal places `celsius`, that denotes the **temperature in Celsius**.
15+
16+
You should convert Celsius into **Kelvin** and **Fahrenheit** and return it as an array `ans = [kelvin, fahrenheit]`.
17+
18+
Return *the array ans.*Answers within `10-5` of the actual answer will be accepted.
19+
20+
**Note that:**
21+
22+
- `Kelvin = Celsius + 273.15`
23+
- `Fahrenheit = Celsius * 1.80 + 32.00`
24+
25+
**Example 1:**
26+
27+
```
28+
Input: celsius = 36.50
29+
Output: [309.65000,97.70000]
30+
Explanation: Temperature at 36.50 Celsius converted in Kelvin is 309.65 and converted in Fahrenheit is 97.70.
31+
```
32+
33+
**Example 2:**
34+
35+
```
36+
Input: celsius = 122.11
37+
Output: [395.26000,251.79800]
38+
Explanation: Temperature at 122.11 Celsius converted in Kelvin is 395.26 and converted in Fahrenheit is 251.798.
39+
```
40+
41+
**Constraints:**
42+
43+
- `0 <= celsius <= 1000`
44+
45+
## Approach 1: Just do it
46+
47+
- Kelvin = Celsius + 273.15
48+
- Fahrenheit = Celsius * 1.80 + 32.00
49+
50+
<Tabs>
51+
<TabItem value="cpp" label="C++">
52+
<SolutionAuthor name="@wingkwong"/>
53+
54+
```cpp
55+
class Solution {
56+
public:
57+
vector<double> convertTemperature(double celsius) {
58+
return {
59+
celsius + 273.15,
60+
celsius * 1.80 + 32.00
61+
};
62+
}
63+
};
64+
```
65+
66+
</TabItem>
67+
</Tabs>

0 commit comments

Comments
 (0)