Skip to content

Commit 3cd9a0b

Browse files
committed
chore: update lc problems
1 parent 7ab0647 commit 3cd9a0b

File tree

122 files changed

+471
-246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+471
-246
lines changed

.github/workflows/prettier.yml

-23
This file was deleted.

.prettierrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"trailingComma": "all",
77
"bracketSpacing": true,
88
"arrowParens": "avoid",
9-
"phpVersion": "8.1"
9+
"phpVersion": "8.1",
10+
"braceStyle": "1tbs"
1011
}

lcof/面试题05. 替换空格/README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,13 @@ class Solution {
227227
* @return String
228228
*/
229229
function replaceSpace($s) {
230-
$rs = "";
230+
$rs = '';
231231
for ($i = 0; $i < strlen($s); $i++) {
232-
if ($s[$i] === " ") $rs = $rs."%20";
233-
else $rs = $rs.$s[$i];
232+
if ($s[$i] === ' ') {
233+
$rs = $rs . '%20';
234+
} else {
235+
$rs = $rs . $s[$i];
236+
}
234237
}
235238
return $rs;
236239
}

solution/0000-0099/0001.Two Sum/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ proc twoSum(nums: seq[int], target: int): seq[int] =
238238

239239
```php
240240
class Solution {
241-
242241
/**
243242
* @param Integer[] $nums
244243
* @param Integer $target

solution/0000-0099/0001.Two Sum/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ proc twoSum(nums: seq[int], target: int): seq[int] =
227227

228228
```php
229229
class Solution {
230-
231230
/**
232231
* @param Integer[] $nums
233232
* @param Integer $target

solution/0000-0099/0013.Roman to Integer/README.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,24 @@ class Solution {
243243
* @return Integer
244244
*/
245245
function romanToInt($s) {
246-
$hashmap = array('I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000);
246+
$hashmap = [
247+
'I' => 1,
248+
'V' => 5,
249+
'X' => 10,
250+
'L' => 50,
251+
'C' => 100,
252+
'D' => 500,
253+
'M' => 1000,
254+
];
247255
$rs = 0;
248256
for ($i = 0; $i < strlen($s); $i++) {
249257
$left = $hashmap[$s[$i]];
250258
$right = $hashmap[$s[$i + 1]];
251-
if ($left >= $right) $rs += $left;
252-
else $rs -= $left;
259+
if ($left >= $right) {
260+
$rs += $left;
261+
} else {
262+
$rs -= $left;
263+
}
253264
}
254265
return $rs;
255266
}

solution/0000-0099/0013.Roman to Integer/README_EN.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,24 @@ class Solution {
221221
* @return Integer
222222
*/
223223
function romanToInt($s) {
224-
$hashmap = array('I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000);
224+
$hashmap = [
225+
'I' => 1,
226+
'V' => 5,
227+
'X' => 10,
228+
'L' => 50,
229+
'C' => 100,
230+
'D' => 500,
231+
'M' => 1000,
232+
];
225233
$rs = 0;
226234
for ($i = 0; $i < strlen($s); $i++) {
227235
$left = $hashmap[$s[$i]];
228236
$right = $hashmap[$s[$i + 1]];
229-
if ($left >= $right) $rs += $left;
230-
else $rs -= $left;
237+
if ($left >= $right) {
238+
$rs += $left;
239+
} else {
240+
$rs -= $left;
241+
}
231242
}
232243
return $rs;
233244
}

solution/0000-0099/0014.Longest Common Prefix/README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,14 @@ class Solution {
228228
* @return String
229229
*/
230230
function longestCommonPrefix($strs) {
231-
$rs = "";
231+
$rs = '';
232232
for ($i = 0; $i < strlen($strs[0]); $i++) {
233233
for ($j = 1; $j < count($strs); $j++) {
234-
if ($strs[0][$i] != $strs[$j][$i]) return $rs;
234+
if ($strs[0][$i] != $strs[$j][$i]) {
235+
return $rs;
236+
}
235237
}
236-
$rs = $rs.$strs[0][$i];
238+
$rs = $rs . $strs[0][$i];
237239
}
238240
return $rs;
239241
}

solution/0000-0099/0014.Longest Common Prefix/README_EN.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,14 @@ class Solution {
219219
* @return String
220220
*/
221221
function longestCommonPrefix($strs) {
222-
$rs = "";
222+
$rs = '';
223223
for ($i = 0; $i < strlen($strs[0]); $i++) {
224224
for ($j = 1; $j < count($strs); $j++) {
225-
if ($strs[0][$i] != $strs[$j][$i]) return $rs;
225+
if ($strs[0][$i] != $strs[$j][$i]) {
226+
return $rs;
227+
}
226228
}
227-
$rs = $rs.$strs[0][$i];
229+
$rs = $rs . $strs[0][$i];
228230
}
229231
return $rs;
230232
}

solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,13 @@ impl Solution {
229229

230230
```php
231231
class Solution {
232-
233232
/**
234233
* @param Integer[] $nums
235234
* @return Integer
236235
*/
237236
function removeDuplicates(&$nums) {
238237
$k = 0;
239-
foreach($nums as $x) {
238+
foreach ($nums as $x) {
240239
if ($k == 0 || $x != $nums[$k - 1]) {
241240
$nums[$k++] = $x;
242241
}

solution/0000-0099/0026.Remove Duplicates from Sorted Array/README_EN.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,13 @@ impl Solution {
203203

204204
```php
205205
class Solution {
206-
207206
/**
208207
* @param Integer[] $nums
209208
* @return Integer
210209
*/
211210
function removeDuplicates(&$nums) {
212211
$k = 0;
213-
foreach($nums as $x) {
212+
foreach ($nums as $x) {
214213
if ($k == 0 || $x != $nums[$k - 1]) {
215214
$nums[$k++] = $x;
216215
}

solution/0000-0099/0027.Remove Element/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ impl Solution {
196196

197197
```php
198198
class Solution {
199-
200199
/**
201200
* @param Integer[] $nums
202201
* @param Integer $val

solution/0000-0099/0027.Remove Element/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ impl Solution {
192192

193193
```php
194194
class Solution {
195-
196195
/**
197196
* @param Integer[] $nums
198197
* @param Integer $val

solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,11 @@ class Solution {
355355
* @return Integer
356356
*/
357357
function strStr($haystack, $needle) {
358-
$strNew = str_replace($needle, "+", $haystack);
359-
$cnt = substr_count($strNew, "+");
358+
$strNew = str_replace($needle, '+', $haystack);
359+
$cnt = substr_count($strNew, '+');
360360
if ($cnt > 0) {
361361
for ($i = 0; $i < strlen($strNew); $i++) {
362-
if ($strNew[$i] == "+") {
362+
if ($strNew[$i] == '+') {
363363
return $i;
364364
}
365365
}

solution/0000-0099/0028.Find the Index of the First Occurrence in a String/README_EN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,11 @@ class Solution {
341341
* @return Integer
342342
*/
343343
function strStr($haystack, $needle) {
344-
$strNew = str_replace($needle, "+", $haystack);
345-
$cnt = substr_count($strNew, "+");
344+
$strNew = str_replace($needle, '+', $haystack);
345+
$cnt = substr_count($strNew, '+');
346346
if ($cnt > 0) {
347347
for ($i = 0; $i < strlen($strNew); $i++) {
348-
if ($strNew[$i] == "+") {
348+
if ($strNew[$i] == '+') {
349349
return $i;
350350
}
351351
}

solution/0000-0099/0058.Length of Last Word/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,10 @@ class Solution {
210210
*/
211211
function lengthOfLastWord($s) {
212212
$count = 0;
213-
while ($s[strlen($s) - 1] == " ") {
213+
while ($s[strlen($s) - 1] == ' ') {
214214
$s = substr($s, 0, -1);
215215
}
216-
while (strlen($s) != 0 && $s[strlen($s) - 1] != " ") {
216+
while (strlen($s) != 0 && $s[strlen($s) - 1] != ' ') {
217217
$count++;
218218
$s = substr($s, 0, -1);
219219
}

solution/0000-0099/0058.Length of Last Word/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ class Solution {
200200
*/
201201
function lengthOfLastWord($s) {
202202
$count = 0;
203-
while ($s[strlen($s) - 1] == " ") {
203+
while ($s[strlen($s) - 1] == ' ') {
204204
$s = substr($s, 0, -1);
205205
}
206-
while (strlen($s) != 0 && $s[strlen($s) - 1] != " ") {
206+
while (strlen($s) != 0 && $s[strlen($s) - 1] != ' ') {
207207
$count++;
208208
$s = substr($s, 0, -1);
209209
}

solution/0100-0199/0100.Same Tree/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -589,16 +589,17 @@ class Solution {
589589
* @return Boolean
590590
*/
591591
function isSameTree($p, $q) {
592-
if ($p == Null && $q == Null) {
592+
if ($p == null && $q == null) {
593593
return true;
594594
}
595-
if ($p == Null || $q == Null) {
595+
if ($p == null || $q == null) {
596596
return false;
597597
}
598598
if ($p->val != $q->val) {
599599
return false;
600600
}
601-
return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right);
601+
return $this->isSameTree($p->left, $q->left) &&
602+
$this->isSameTree($p->right, $q->right);
602603
}
603604
}
604605
```

solution/0100-0199/0100.Same Tree/README_EN.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -561,16 +561,17 @@ class Solution {
561561
* @return Boolean
562562
*/
563563
function isSameTree($p, $q) {
564-
if ($p == Null && $q == Null) {
564+
if ($p == null && $q == null) {
565565
return true;
566566
}
567-
if ($p == Null || $q == Null) {
567+
if ($p == null || $q == null) {
568568
return false;
569569
}
570570
if ($p->val != $q->val) {
571571
return false;
572572
}
573-
return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right);
573+
return $this->isSameTree($p->left, $q->left) &&
574+
$this->isSameTree($p->right, $q->right);
574575
}
575576
}
576577
```

solution/0100-0199/0125.Valid Palindrome/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,12 @@ class Solution {
273273
* @return Boolean
274274
*/
275275
function isPalindrome($s) {
276-
$regex = "/[a-z0-9]/";
276+
$regex = '/[a-z0-9]/';
277277
$s = strtolower($s);
278278
preg_match_all($regex, $s, $matches);
279-
if ($matches[0] == Null) return true;
279+
if ($matches[0] == null) {
280+
return true;
281+
}
280282
$len = floor(count($matches[0]) / 2);
281283
for ($i = 0; $i < $len; $i++) {
282284
if ($matches[0][$i] != $matches[0][count($matches[0]) - 1 - $i]) {

solution/0100-0199/0125.Valid Palindrome/README_EN.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,12 @@ class Solution {
248248
* @return Boolean
249249
*/
250250
function isPalindrome($s) {
251-
$regex = "/[a-z0-9]/";
251+
$regex = '/[a-z0-9]/';
252252
$s = strtolower($s);
253253
preg_match_all($regex, $s, $matches);
254-
if ($matches[0] == Null) return true;
254+
if ($matches[0] == null) {
255+
return true;
256+
}
255257
$len = floor(count($matches[0]) / 2);
256258
for ($i = 0; $i < $len; $i++) {
257259
if ($matches[0][$i] != $matches[0][count($matches[0]) - 1 - $i]) {

solution/0100-0199/0169.Majority Element/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ impl Solution {
217217

218218
```php
219219
class Solution {
220-
221220
/**
222221
* @param Integer[] $nums
223222
* @return Integer

solution/0100-0199/0169.Majority Element/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ impl Solution {
201201

202202
```php
203203
class Solution {
204-
205204
/**
206205
* @param Integer[] $nums
207206
* @return Integer

solution/0200-0299/0229.Majority Element II/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,9 @@ class Solution {
243243
$n = count($nums);
244244
for ($i = 0; $i < $n; $i++) {
245245
$hashmap[$nums[$i]] += 1;
246-
if ($hashmap[$nums[$i]] > $n / 3)
246+
if ($hashmap[$nums[$i]] > $n / 3) {
247247
array_push($rs, $nums[$i]);
248+
}
248249
}
249250
return array_unique($rs);
250251
}

solution/0200-0299/0229.Majority Element II/README_EN.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ class Solution {
232232
$n = count($nums);
233233
for ($i = 0; $i < $n; $i++) {
234234
$hashmap[$nums[$i]] += 1;
235-
if ($hashmap[$nums[$i]] > $n / 3)
235+
if ($hashmap[$nums[$i]] > $n / 3) {
236236
array_push($rs, $nums[$i]);
237+
}
237238
}
238239
return array_unique($rs);
239240
}

solution/0200-0299/0263.Ugly Number/README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,15 @@ class Solution {
160160
*/
161161
function isUgly($n) {
162162
while ($n) {
163-
if ($n % 2 == 0) $n = $n / 2;
164-
else if ($n % 3 == 0) $n = $n / 3;
165-
else if ($n % 5 == 0) $n = $n / 5;
166-
else break;
163+
if ($n % 2 == 0) {
164+
$n = $n / 2;
165+
} elseif ($n % 3 == 0) {
166+
$n = $n / 3;
167+
} elseif ($n % 5 == 0) {
168+
$n = $n / 5;
169+
} else {
170+
break;
171+
}
167172
}
168173
return $n == 1;
169174
}

0 commit comments

Comments
 (0)