Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0dd1c7d

Browse files
committed
feat: add solutions to lc problems: No.1920, 2396
- No.1920.Build Array from Permutation - No.2396.Strictly Palindromic Number
1 parent fd1e316 commit 0dd1c7d

File tree

10 files changed

+170
-32
lines changed

10 files changed

+170
-32
lines changed

‎solution/1900-1999/1920.Build Array from Permutation/README.md‎

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,6 @@ class Solution {
7272
}
7373
```
7474

75-
### **JavaScript**
76-
77-
```js
78-
/**
79-
* @param {number[]} nums
80-
* @return {number[]}
81-
*/
82-
var buildArray = function (nums) {
83-
let ans = [];
84-
for (let i = 0; i < nums.length; ++i) {
85-
ans[i] = nums[nums[i]];
86-
}
87-
return ans;
88-
};
89-
```
90-
9175
### **C++**
9276

9377
```cpp
@@ -115,6 +99,56 @@ func buildArray(nums []int) []int {
11599
}
116100
```
117101

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

‎solution/1900-1999/1920.Build Array from Permutation/README_EN.md‎

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,6 @@ class Solution {
6767
}
6868
```
6969

70-
### **JavaScript**
71-
72-
```js
73-
/**
74-
* @param {number[]} nums
75-
* @return {number[]}
76-
*/
77-
var buildArray = function (nums) {
78-
let ans = [];
79-
for (let i = 0; i < nums.length; ++i) {
80-
ans[i] = nums[nums[i]];
81-
}
82-
return ans;
83-
};
84-
```
85-
8670
### **C++**
8771

8872
```cpp
@@ -110,6 +94,56 @@ func buildArray(nums []int) []int {
11094
}
11195
```
11296

97+
### **JavaScript**
98+
99+
```js
100+
/**
101+
* @param {number[]} nums
102+
* @return {number[]}
103+
*/
104+
var buildArray = function (nums) {
105+
let ans = [];
106+
for (let i = 0; i < nums.length; ++i) {
107+
ans[i] = nums[nums[i]];
108+
}
109+
return ans;
110+
};
111+
```
112+
113+
### **TypeScript**
114+
115+
```ts
116+
function buildArray(nums: number[]): number[] {
117+
return nums.map(v => nums[v]);
118+
}
119+
```
120+
121+
### **Rust**
122+
123+
```rust
124+
impl Solution {
125+
pub fn build_array(nums: Vec<i32>) -> Vec<i32> {
126+
nums.iter().map(|&v| nums[v as usize]).collect()
127+
}
128+
}
129+
```
130+
131+
### **C**
132+
133+
```c
134+
/**
135+
* Note: The returned array must be malloced, assume caller calls free().
136+
*/
137+
int *buildArray(int *nums, int numsSize, int *returnSize) {
138+
int *ans = malloc(sizeof(int) * numsSize);
139+
for (int i = 0; i < numsSize; i++) {
140+
ans[i] = nums[nums[i]];
141+
}
142+
*returnSize = numsSize;
143+
return ans;
144+
}
145+
```
146+
113147
### **...**
114148
115149
```
Lines changed: 11 additions & 0 deletions
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 *buildArray(int *nums, int numsSize, int *returnSize) {
5+
int *ans = malloc(sizeof(int) * numsSize);
6+
for (int i = 0; i < numsSize; i++) {
7+
ans[i] = nums[nums[i]];
8+
}
9+
*returnSize = numsSize;
10+
return ans;
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
impl Solution {
2+
pub fn build_array(nums: Vec<i32>) -> Vec<i32> {
3+
nums.iter().map(|&v| nums[v as usize]).collect()
4+
}
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function buildArray(nums: number[]): number[] {
2+
return nums.map(v => nums[v]);
3+
}

‎solution/2300-2399/2396.Strictly Palindromic Number/README.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,27 @@ func isStrictlyPalindromic(n int) bool {
100100
### **TypeScript**
101101

102102
```ts
103+
function isStrictlyPalindromic(n: number): boolean {
104+
return false;
105+
}
106+
```
107+
108+
### **Rust**
103109

110+
```rust
111+
impl Solution {
112+
pub fn is_strictly_palindromic(n: i32) -> bool {
113+
false
114+
}
115+
}
116+
```
117+
118+
### **C**
119+
120+
```c
121+
bool isStrictlyPalindromic(int n) {
122+
return 0;
123+
}
104124
```
105125
106126
### **...**

‎solution/2300-2399/2396.Strictly Palindromic Number/README_EN.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,27 @@ func isStrictlyPalindromic(n int) bool {
8383
### **TypeScript**
8484

8585
```ts
86+
function isStrictlyPalindromic(n: number): boolean {
87+
return false;
88+
}
89+
```
90+
91+
### **Rust**
8692

93+
```rust
94+
impl Solution {
95+
pub fn is_strictly_palindromic(n: i32) -> bool {
96+
false
97+
}
98+
}
99+
```
100+
101+
### **C**
102+
103+
```c
104+
bool isStrictlyPalindromic(int n) {
105+
return 0;
106+
}
87107
```
88108
89109
### **...**
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bool isStrictlyPalindromic(int n) {
2+
return 0;
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
impl Solution {
2+
pub fn is_strictly_palindromic(n: i32) -> bool {
3+
false
4+
}
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function isStrictlyPalindromic(n: number): boolean {
2+
return false;
3+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /