Skip to content

Commit e7cee73

Browse files
committed
feat: add solutions to lc problems: No.1929, 2235
- No.1929.Concatenation of Array - No.2235.Add Two Integers
1 parent 0fcf785 commit e7cee73

File tree

9 files changed

+175
-28
lines changed

9 files changed

+175
-28
lines changed

solution/1900-1999/1929.Concatenation of Array/README.md

+48-14
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,6 @@ class Solution {
8181
}
8282
```
8383

84-
### **JavaScript**
85-
86-
```js
87-
/**
88-
* @param {number[]} nums
89-
* @return {number[]}
90-
*/
91-
var getConcatenation = function (nums) {
92-
let ans = nums.slice();
93-
ans.splice(nums.length, 0, ...nums);
94-
return ans;
95-
};
96-
```
97-
9884
### **C++**
9985

10086
```cpp
@@ -117,6 +103,54 @@ func getConcatenation(nums []int) []int {
117103
}
118104
```
119105

106+
### **JavaScript**
107+
108+
```js
109+
/**
110+
* @param {number[]} nums
111+
* @return {number[]}
112+
*/
113+
var getConcatenation = function (nums) {
114+
let ans = nums.slice();
115+
ans.splice(nums.length, 0, ...nums);
116+
return ans;
117+
};
118+
```
119+
120+
### **TypeScript**
121+
122+
```ts
123+
function getConcatenation(nums: number[]): number[] {
124+
return [...nums, ...nums];
125+
}
126+
```
127+
128+
### **Rust**
129+
130+
```rust
131+
impl Solution {
132+
pub fn get_concatenation(nums: Vec<i32>) -> Vec<i32> {
133+
nums.repeat(2)
134+
}
135+
}
136+
```
137+
138+
### **C**
139+
140+
```c
141+
/**
142+
* Note: The returned array must be malloced, assume caller calls free().
143+
*/
144+
int *getConcatenation(int *nums, int numsSize, int *returnSize) {
145+
int *ans = malloc(sizeof(int) * numsSize * 2);
146+
for (int i = 0; i < numsSize; i++) {
147+
ans[i] = ans[i + numsSize] = nums[i];
148+
}
149+
*returnSize = numsSize * 2;
150+
return ans;
151+
}
152+
```
153+
120154
### **...**
121155
122156
```

solution/1900-1999/1929.Concatenation of Array/README_EN.md

+48-14
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,6 @@ class Solution {
6666
}
6767
```
6868

69-
### **JavaScript**
70-
71-
```js
72-
/**
73-
* @param {number[]} nums
74-
* @return {number[]}
75-
*/
76-
var getConcatenation = function (nums) {
77-
let ans = nums.slice();
78-
ans.splice(nums.length, 0, ...nums);
79-
return ans;
80-
};
81-
```
82-
8369
### **C++**
8470

8571
```cpp
@@ -102,6 +88,54 @@ func getConcatenation(nums []int) []int {
10288
}
10389
```
10490

91+
### **JavaScript**
92+
93+
```js
94+
/**
95+
* @param {number[]} nums
96+
* @return {number[]}
97+
*/
98+
var getConcatenation = function (nums) {
99+
let ans = nums.slice();
100+
ans.splice(nums.length, 0, ...nums);
101+
return ans;
102+
};
103+
```
104+
105+
### **TypeScript**
106+
107+
```ts
108+
function getConcatenation(nums: number[]): number[] {
109+
return [...nums, ...nums];
110+
}
111+
```
112+
113+
### **Rust**
114+
115+
```rust
116+
impl Solution {
117+
pub fn get_concatenation(nums: Vec<i32>) -> Vec<i32> {
118+
nums.repeat(2)
119+
}
120+
}
121+
```
122+
123+
### **C**
124+
125+
```c
126+
/**
127+
* Note: The returned array must be malloced, assume caller calls free().
128+
*/
129+
int *getConcatenation(int *nums, int numsSize, int *returnSize) {
130+
int *ans = malloc(sizeof(int) * numsSize * 2);
131+
for (int i = 0; i < numsSize; i++) {
132+
ans[i] = ans[i + numsSize] = nums[i];
133+
}
134+
*returnSize = numsSize * 2;
135+
return ans;
136+
}
137+
```
138+
105139
### **...**
106140
107141
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Note: The returned array must be malloced, assume caller calls free().
3+
*/
4+
int *getConcatenation(int *nums, int numsSize, int *returnSize) {
5+
int *ans = malloc(sizeof(int) * numsSize * 2);
6+
for (int i = 0; i < numsSize; i++) {
7+
ans[i] = ans[i + numsSize] = nums[i];
8+
}
9+
*returnSize = numsSize * 2;
10+
return ans;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
impl Solution {
2+
pub fn get_concatenation(nums: Vec<i32>) -> Vec<i32> {
3+
nums.repeat(2)
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function getConcatenation(nums: number[]): number[] {
2+
return [...nums, ...nums];
3+
}

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

+26
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,32 @@ func sum(num1 int, num2 int) int {
8989
}
9090
```
9191

92+
### **TypeScript**
93+
94+
```ts
95+
function sum(num1: number, num2: number): number {
96+
return num1 + num2;
97+
}
98+
```
99+
100+
### **Rust**
101+
102+
```rust
103+
impl Solution {
104+
pub fn sum(num1: i32, num2: i32) -> i32 {
105+
num1 + num2
106+
}
107+
}
108+
```
109+
110+
### **C**
111+
112+
```c
113+
int sum(int num1, int num2) {
114+
return num1 + num2;
115+
}
116+
```
117+
92118
### **...**
93119
94120
```

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

+26
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,32 @@ func sum(num1 int, num2 int) int {
7979
}
8080
```
8181

82+
### **TypeScript**
83+
84+
```ts
85+
function sum(num1: number, num2: number): number {
86+
return num1 + num2;
87+
}
88+
```
89+
90+
### **Rust**
91+
92+
```rust
93+
impl Solution {
94+
pub fn sum(num1: i32, num2: i32) -> i32 {
95+
num1 + num2
96+
}
97+
}
98+
```
99+
100+
### **C**
101+
102+
```c
103+
int sum(int num1, int num2) {
104+
return num1 + num2;
105+
}
106+
```
107+
82108
### **...**
83109
84110
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int sum(int num1, int num2) {
2+
return num1 + num2;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
impl Solution {
2+
pub fn sum(num1: i32, num2: i32) -> i32 {
3+
num1 + num2
4+
}
5+
}

0 commit comments

Comments
 (0)