Skip to content

Commit afb406c

Browse files
committed
feat: add solutions to lc problems
* No.2235.Add Two Integers * No.2236.Root Equals Sum of Children
1 parent 724ebec commit afb406c

File tree

14 files changed

+318
-8
lines changed

14 files changed

+318
-8
lines changed

solution/2200-2299/2235.Add Two Integers/README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,48 @@
4545
<!-- 这里可写当前语言的特殊实现逻辑 -->
4646

4747
```python
48-
48+
class Solution:
49+
def sum(self, num1: int, num2: int) -> int:
50+
return num1 + num2
4951
```
5052

5153
### **Java**
5254

5355
<!-- 这里可写当前语言的特殊实现逻辑 -->
5456

5557
```java
56-
58+
class Solution {
59+
public int sum(int num1, int num2) {
60+
return num1 + num2;
61+
}
62+
}
5763
```
5864

5965
### **TypeScript**
6066

6167
```ts
68+
function sum(num1: number, num2: number): number {
69+
return num1 + num2;
70+
}
71+
```
72+
73+
### **C++**
74+
75+
```cpp
76+
class Solution {
77+
public:
78+
int sum(int num1, int num2) {
79+
return num1 + num2;
80+
}
81+
};
82+
```
83+
84+
### **Go**
6285
86+
```go
87+
func sum(num1 int, num2 int) int {
88+
return num1 + num2
89+
}
6390
```
6491

6592
### **...**

solution/2200-2299/2235.Add Two Integers/README_EN.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,46 @@ Given two integers <code>num1</code> and <code>num2</code>, return <em>the <stro
3737
### **Python3**
3838

3939
```python
40-
40+
class Solution:
41+
def sum(self, num1: int, num2: int) -> int:
42+
return num1 + num2
4143
```
4244

4345
### **Java**
4446

4547
```java
46-
48+
class Solution {
49+
public int sum(int num1, int num2) {
50+
return num1 + num2;
51+
}
52+
}
4753
```
4854

4955
### **TypeScript**
5056

5157
```ts
58+
function sum(num1: number, num2: number): number {
59+
return num1 + num2;
60+
}
61+
```
62+
63+
### **C++**
64+
65+
```cpp
66+
class Solution {
67+
public:
68+
int sum(int num1, int num2) {
69+
return num1 + num2;
70+
}
71+
};
72+
```
73+
74+
### **Go**
5275
76+
```go
77+
func sum(num1 int, num2 int) int {
78+
return num1 + num2
79+
}
5380
```
5481

5582
### **...**
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Solution {
2+
public:
3+
int sum(int num1, int num2) {
4+
return num1 + num2;
5+
}
6+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
func sum(num1 int, num2 int) int {
2+
return num1 + num2
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Solution {
2+
public int sum(int num1, int num2) {
3+
return num1 + num2;
4+
}
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def sum(self, num1: int, num2: int) -> int:
3+
return num1 + num2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function sum(num1: number, num2: number): number {
2+
return num1 + num2;
3+
}

solution/2200-2299/2236.Root Equals Sum of Children/README.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,102 @@
5151
<!-- 这里可写当前语言的特殊实现逻辑 -->
5252

5353
```python
54-
54+
# Definition for a binary tree node.
55+
# class TreeNode:
56+
# def __init__(self, val=0, left=None, right=None):
57+
# self.val = val
58+
# self.left = left
59+
# self.right = right
60+
class Solution:
61+
def checkTree(self, root: Optional[TreeNode]) -> bool:
62+
return root.val == root.left.val + root.right.val
5563
```
5664

5765
### **Java**
5866

5967
<!-- 这里可写当前语言的特殊实现逻辑 -->
6068

6169
```java
62-
70+
/**
71+
* Definition for a binary tree node.
72+
* public class TreeNode {
73+
* int val;
74+
* TreeNode left;
75+
* TreeNode right;
76+
* TreeNode() {}
77+
* TreeNode(int val) { this.val = val; }
78+
* TreeNode(int val, TreeNode left, TreeNode right) {
79+
* this.val = val;
80+
* this.left = left;
81+
* this.right = right;
82+
* }
83+
* }
84+
*/
85+
class Solution {
86+
public boolean checkTree(TreeNode root) {
87+
return root.val == root.left.val + root.right.val;
88+
}
89+
}
6390
```
6491

6592
### **TypeScript**
6693

6794
```ts
95+
/**
96+
* Definition for a binary tree node.
97+
* class TreeNode {
98+
* val: number
99+
* left: TreeNode | null
100+
* right: TreeNode | null
101+
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
102+
* this.val = (val===undefined ? 0 : val)
103+
* this.left = (left===undefined ? null : left)
104+
* this.right = (right===undefined ? null : right)
105+
* }
106+
* }
107+
*/
108+
109+
function checkTree(root: TreeNode | null): boolean {
110+
return root.val === root.left.val + root.right.val;
111+
}
112+
```
113+
114+
### **C++**
115+
116+
```cpp
117+
/**
118+
* Definition for a binary tree node.
119+
* struct TreeNode {
120+
* int val;
121+
* TreeNode *left;
122+
* TreeNode *right;
123+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
124+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
125+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
126+
* };
127+
*/
128+
class Solution {
129+
public:
130+
bool checkTree(TreeNode* root) {
131+
return root->val == root->left->val + root->right->val;
132+
}
133+
};
134+
```
68135
136+
### **Go**
137+
138+
```go
139+
/**
140+
* Definition for a binary tree node.
141+
* type TreeNode struct {
142+
* Val int
143+
* Left *TreeNode
144+
* Right *TreeNode
145+
* }
146+
*/
147+
func checkTree(root *TreeNode) bool {
148+
return root.Val == root.Left.Val+root.Right.Val
149+
}
69150
```
70151

71152
### **...**

solution/2200-2299/2236.Root Equals Sum of Children/README_EN.md

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,100 @@
4343
### **Python3**
4444

4545
```python
46-
46+
# Definition for a binary tree node.
47+
# class TreeNode:
48+
# def __init__(self, val=0, left=None, right=None):
49+
# self.val = val
50+
# self.left = left
51+
# self.right = right
52+
class Solution:
53+
def checkTree(self, root: Optional[TreeNode]) -> bool:
54+
return root.val == root.left.val + root.right.val
4755
```
4856

4957
### **Java**
5058

5159
```java
52-
60+
/**
61+
* Definition for a binary tree node.
62+
* public class TreeNode {
63+
* int val;
64+
* TreeNode left;
65+
* TreeNode right;
66+
* TreeNode() {}
67+
* TreeNode(int val) { this.val = val; }
68+
* TreeNode(int val, TreeNode left, TreeNode right) {
69+
* this.val = val;
70+
* this.left = left;
71+
* this.right = right;
72+
* }
73+
* }
74+
*/
75+
class Solution {
76+
public boolean checkTree(TreeNode root) {
77+
return root.val == root.left.val + root.right.val;
78+
}
79+
}
5380
```
5481

5582
### **TypeScript**
5683

5784
```ts
85+
/**
86+
* Definition for a binary tree node.
87+
* class TreeNode {
88+
* val: number
89+
* left: TreeNode | null
90+
* right: TreeNode | null
91+
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
92+
* this.val = (val===undefined ? 0 : val)
93+
* this.left = (left===undefined ? null : left)
94+
* this.right = (right===undefined ? null : right)
95+
* }
96+
* }
97+
*/
98+
99+
function checkTree(root: TreeNode | null): boolean {
100+
return root.val === root.left.val + root.right.val;
101+
}
102+
```
103+
104+
### **C++**
105+
106+
```cpp
107+
/**
108+
* Definition for a binary tree node.
109+
* struct TreeNode {
110+
* int val;
111+
* TreeNode *left;
112+
* TreeNode *right;
113+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
114+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
115+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
116+
* };
117+
*/
118+
class Solution {
119+
public:
120+
bool checkTree(TreeNode* root) {
121+
return root->val == root->left->val + root->right->val;
122+
}
123+
};
124+
```
58125
126+
### **Go**
127+
128+
```go
129+
/**
130+
* Definition for a binary tree node.
131+
* type TreeNode struct {
132+
* Val int
133+
* Left *TreeNode
134+
* Right *TreeNode
135+
* }
136+
*/
137+
func checkTree(root *TreeNode) bool {
138+
return root.Val == root.Left.Val+root.Right.Val
139+
}
59140
```
60141

61142
### **...**
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
8+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
9+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
10+
* };
11+
*/
12+
class Solution {
13+
public:
14+
bool checkTree(TreeNode* root) {
15+
return root->val == root->left->val + root->right->val;
16+
}
17+
};

0 commit comments

Comments
 (0)