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

[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
pull merged 14 commits into FairyWorld:main from doocs:main
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
1f57e5e
chore: auto compress images
yanglbme Mar 29, 2023
526b902
feat: add solutions to lc problem: No.1643
yanglbme Mar 29, 2023
e43dd02
feat: add solutions to lc problem: No.1637
yanglbme Mar 29, 2023
24d191c
feat: add solutions to lc problem: No.1655
yanglbme Mar 29, 2023
f51d868
feat: add php solution to lc problem: No.0769 (#957)
Qiu-IT Mar 29, 2023
707af68
feat: add solutions to lc problem: No.2427
yanglbme Mar 29, 2023
7e91d18
feat: update solutions to lc problem: No.2428
yanglbme Mar 29, 2023
0212990
feat: update solutions to lc problem: No.12
thinkasany Mar 29, 2023
4250319
feat: add solutions to lc problem: No.1637
yanglbme Mar 30, 2023
afd72a6
feat: add golang solution to lc problem: No.0087 (#959)
atompi Mar 30, 2023
a615012
feat: add solutions to lc problem: No.1854
yanglbme Mar 30, 2023
ca289c7
feat: add solutions to lc problem: No.1856
yanglbme Mar 30, 2023
1b8e686
feat: add php solution to lc problem: No.0349 (#960)
Qiu-IT Mar 30, 2023
72aac94
feat: add solutions to lc problem: No.2367
yanglbme Mar 30, 2023
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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
View file Open in desktop
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;
}
}
View file Open in desktop
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

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