Skip to content

[pull] main from doocs:main #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions solution/0000-0099/0012.Integer to Roman/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,39 @@ func intToRoman(num int) string {
}
```

### **TypeScript**

```ts
function intToRoman(num: number): string {
const nums: number[] = [
1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1,
];
const romans: string[] = [
'M',
'CM',
'D',
'CD',
'C',
'XC',
'L',
'XL',
'X',
'IX',
'V',
'IV',
'I',
];
let ans: string = '';
for (let i = 0; i < nums.length; ++i) {
while (num >= nums[i]) {
num -= nums[i];
ans += romans[i];
}
}
return ans;
}
```

### **...**

```
Expand Down
33 changes: 33 additions & 0 deletions solution/0000-0099/0012.Integer to Roman/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,39 @@ func intToRoman(num int) string {
}
```

### **TypeScript**

```ts
function intToRoman(num: number): string {
const nums: number[] = [
1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1,
];
const romans: string[] = [
'M',
'CM',
'D',
'CD',
'C',
'XC',
'L',
'XL',
'X',
'IX',
'V',
'IV',
'I',
];
let ans: string = '';
for (let i = 0; i < nums.length; ++i) {
while (num >= nums[i]) {
num -= nums[i];
ans += romans[i];
}
}
return ans;
}
```

### **...**

```
Expand Down
28 changes: 28 additions & 0 deletions solution/0000-0099/0012.Integer to Roman/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function intToRoman(num: number): string {
const nums: number[] = [
1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1,
];
const romans: string[] = [
'M',
'CM',
'D',
'CD',
'C',
'XC',
'L',
'XL',
'X',
'IX',
'V',
'IV',
'I',
];
let ans: string = '';
for (let i = 0; i < nums.length; ++i) {
while (num >= nums[i]) {
num -= nums[i];
ans += romans[i];
}
}
return ans;
}
37 changes: 37 additions & 0 deletions solution/0000-0099/0087.Scramble String/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,43 @@ class Solution {
}
```

### **Go**

```go
func isScramble(s1 string, s2 string) bool {
n := len(s1)
dp := make([][][]bool, n+1)
for i := range dp {
dp[i] = make([][]bool, n)
for j := range dp[i] {
dp[i][j] = make([]bool, n+1)
}
}
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
dp[i][j][1] = s1[i] == s2[j]
}
}
for l := 2; l < n+1; l++ {
for i1 := 0; i1 < n-l+1; i1++ {
for i2 := 0; i2 < n-l+1; i2++ {
for i := 1; i < l; i++ {
if dp[i1][i2][i] && dp[i1+i][i2+i][l-i] {
dp[i1][i2][l] = true
break
}
if dp[i1][i2+l-i][i] && dp[i1+i][i2][l-i] {
dp[i1][i2][l] = true
break
}
}
}
}
}
return dp[0][0][n]
}
```

### **...**

```
Expand Down
37 changes: 37 additions & 0 deletions solution/0000-0099/0087.Scramble String/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,43 @@ class Solution {
}
```

### **Go**

```go
func isScramble(s1 string, s2 string) bool {
n := len(s1)
dp := make([][][]bool, n+1)
for i := range dp {
dp[i] = make([][]bool, n)
for j := range dp[i] {
dp[i][j] = make([]bool, n+1)
}
}
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
dp[i][j][1] = s1[i] == s2[j]
}
}
for l := 2; l < n+1; l++ {
for i1 := 0; i1 < n-l+1; i1++ {
for i2 := 0; i2 < n-l+1; i2++ {
for i := 1; i < l; i++ {
if dp[i1][i2][i] && dp[i1+i][i2+i][l-i] {
dp[i1][i2][l] = true
break
}
if dp[i1][i2+l-i][i] && dp[i1+i][i2][l-i] {
dp[i1][i2][l] = true
break
}
}
}
}
}
return dp[0][0][n]
}
```

### **...**

```
Expand Down
32 changes: 32 additions & 0 deletions solution/0000-0099/0087.Scramble String/Solution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
func isScramble(s1 string, s2 string) bool {
n := len(s1)
dp := make([][][]bool, n+1)
for i := range dp {
dp[i] = make([][]bool, n)
for j := range dp[i] {
dp[i][j] = make([]bool, n+1)
}
}
for i := 0; i < n; i++ {
for j := 0; j < n; j++ {
dp[i][j][1] = s1[i] == s2[j]
}
}
for l := 2; l < n+1; l++ {
for i1 := 0; i1 < n-l+1; i1++ {
for i2 := 0; i2 < n-l+1; i2++ {
for i := 1; i < l; i++ {
if dp[i1][i2][i] && dp[i1+i][i2+i][l-i] {
dp[i1][i2][l] = true
break
}
if dp[i1][i2+l-i][i] && dp[i1+i][i2][l-i] {
dp[i1][i2][l] = true
break
}
}
}
}
}
return dp[0][0][n]
}
24 changes: 24 additions & 0 deletions solution/0300-0399/0349.Intersection of Two Arrays/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,30 @@ func intersection(nums1 []int, nums2 []int) []int {
}
```

### **PHP**

```php
class Solution {
/**
* @param Integer[] $nums1
* @param Integer[] $nums2
* @return Integer[]
*/
function intersection($nums1, $nums2) {
$rs = [];
$set1 = array_values(array_unique($nums1));
$set2 = array_values(array_unique($nums2));
for ($i = 0; $i < count($set1); $i++) {
$hashmap[$set1[$i]] = 1;
}
for ($j = 0; $j < count($set2); $j++) {
if ($hashmap[$set2[$j]]) array_push($rs, $set2[$j]);
}
return $rs;
}
}
```

### **...**

```
Expand Down
24 changes: 24 additions & 0 deletions solution/0300-0399/0349.Intersection of Two Arrays/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,30 @@ func intersection(nums1 []int, nums2 []int) []int {
}
```

### **PHP**

```php
class Solution {
/**
* @param Integer[] $nums1
* @param Integer[] $nums2
* @return Integer[]
*/
function intersection($nums1, $nums2) {
$rs = [];
$set1 = array_values(array_unique($nums1));
$set2 = array_values(array_unique($nums2));
for ($i = 0; $i < count($set1); $i++) {
$hashmap[$set1[$i]] = 1;
}
for ($j = 0; $j < count($set2); $j++) {
if ($hashmap[$set2[$j]]) array_push($rs, $set2[$j]);
}
return $rs;
}
}
```

### **...**

```
Expand Down
19 changes: 19 additions & 0 deletions solution/0300-0399/0349.Intersection of Two Arrays/Solution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
/**
* @param Integer[] $nums1
* @param Integer[] $nums2
* @return Integer[]
*/
function intersection($nums1, $nums2) {
$rs = [];
$set1 = array_values(array_unique($nums1));
$set2 = array_values(array_unique($nums2));
for ($i = 0; $i < count($set1); $i++) {
$hashmap[$set1[$i]] = 1;
}
for ($j = 0; $j < count($set2); $j++) {
if ($hashmap[$set2[$j]]) array_push($rs, $set2[$j]);
}
return $rs;
}
}
15 changes: 15 additions & 0 deletions solution/0700-0799/0796.Rotate String/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ impl Solution {
}
```

### **PHP**

```php
class Solution {
/**
* @param String $s
* @param String $goal
* @return Boolean
*/
function rotateString($s, $goal) {
return strlen($goal) === strlen($s) && strpos(($s.$s), $goal) !== false;
}
}
```

### **...**

```
Expand Down
15 changes: 15 additions & 0 deletions solution/0700-0799/0796.Rotate String/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ impl Solution {
}
```

### **PHP**

```php
class Solution {
/**
* @param String $s
* @param String $goal
* @return Boolean
*/
function rotateString($s, $goal) {
return strlen($goal) === strlen($s) && strpos(($s.$s), $goal) !== false;
}
}
```

### **...**

```
Expand Down
10 changes: 10 additions & 0 deletions solution/0700-0799/0796.Rotate String/Solution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution {
/**
* @param String $s
* @param String $goal
* @return Boolean
*/
function rotateString($s, $goal) {
return strlen($goal) === strlen($s) && strpos(($s.$s), $goal) !== false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@

**方法一:数组或哈希表计数**

用数组或者哈希表统计 `nums` 中每个数字出现的次数,由于题目中数字的范围是 `[-100, 100]`,我们可以直接创建一个大小为 $201$ 的数组来统计。
用数组或者哈希表统计 `nums` 中每个数字出现的次数,由于题目中数字的范围是 $[-100, 100]$,我们可以直接创建一个大小为 $201$ 的数组来统计。

然后对 `nums` 按照数字出现次数升序排序,如果出现次数相同,则按照数字降序排序。

时间复杂度为 $O(n\log n)$,空间复杂度 $O(n)$。其中 $n$ `nums` 的长度。
时间复杂度为 $O(n \times \log n)$,空间复杂度 $O(n)$。其中 $n$ 为数组 `nums` 的长度。

<!-- tabs:start -->

Expand Down
Loading