Skip to content

Commit d191a7f

Browse files
authored
Merge pull request #2008 from Saksham2k3s/add-solution-lc-problem-2235
Added solution for lc problem 2235
2 parents 2d86343 + ba94a8a commit d191a7f

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

dsa-problems/leetcode-problems/2200-2299.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export const problems = [
224224
"problemName": "2235. Add Two Integers",
225225
"difficulty": "Easy",
226226
"leetCodeLink": "https://leetcode.com/problems/add-two-integers",
227-
"solutionLink": "#"
227+
"solutionLink": "/dsa-solutions/lc-solutions/2200-2299/add-two-integers"
228228
},
229229
{
230230
"problemName": "2236. Root Equals Sum of Children",
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
id: add-two-integers
3+
title: Add Two Integers
4+
sidebar_label: 2255 - Add Two Integers
5+
tags:
6+
- Functions
7+
- Arguments
8+
description: Given two integers `num1` and `num2`, return the **sum** of the two integers.
9+
sidebar_position: 2235
10+
---
11+
12+
## Problem Statement
13+
Given two integers `num1` and `num2`, return the **sum** of the two integers.
14+
15+
### Examples
16+
17+
**Example 1:**
18+
19+
```
20+
Input: num1 = 12, num2 = 5
21+
Output: 17
22+
Explination: num1 is 12, num2 is 5, and their sum is 12 + 5 = 17, so 17 is returned.
23+
```
24+
25+
**Example 2:**
26+
27+
```
28+
Input: num1 = -10, num2 = 4
29+
Output: -6
30+
Explination: num1 + num2 = -6, so -6 is returned.
31+
```
32+
33+
34+
35+
### Constraints
36+
37+
- `-100 <= num1, num2 <= 100`
38+
39+
## Solution
40+
41+
#### C++ Implementation
42+
43+
```cpp
44+
class Solution {
45+
public:
46+
int sum(int num1, int num2) {
47+
return num1 + num2;
48+
}
49+
};
50+
```
51+
52+
#### Python Implementation
53+
54+
```python
55+
class Solution:
56+
def sum(self, num1: int, num2: int) -> int:
57+
return num1 + num2
58+
```
59+
60+
#### Java Implementation
61+
62+
```java
63+
class Solution {
64+
public int sum(int num1, int num2) {
65+
return num1 + num2;
66+
}
67+
}
68+
```
69+
70+
#### JavaScript Implementation
71+
72+
```javascript
73+
var sum = function(num1, num2) {
74+
return num1 + num2;
75+
};
76+
```
77+
78+
#### TypeScript Implementation
79+
80+
```typescript
81+
function sum(num1: number, num2: number): number {
82+
return num1 + num2;
83+
};
84+
```
85+
86+
### Conclusion
87+
88+
These implementations handle the addition of two integers and return their sum. The examples provided also show how to use each function. The problem is straightforward and has a constant time complexity of 𝑂(1) for each implementation.

0 commit comments

Comments
 (0)