Skip to content

Commit 08f389e

Browse files
authored
feat: update lc problems (doocs#2185)
1 parent af211c5 commit 08f389e

File tree

171 files changed

+2464
-2465
lines changed

Some content is hidden

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

171 files changed

+2464
-2465
lines changed

lcci/16.04.Tic-Tac-Toe/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ class Solution:
7777
dg += v
7878
if i + j + 1 == n:
7979
udg += v
80-
if abs(rows[i]) == n or abs(cols[j]) == n or abs(dg) == n or abs(udg) == n:
80+
if (
81+
abs(rows[i]) == n
82+
or abs(cols[j]) == n
83+
or abs(dg) == n
84+
or abs(udg) == n
85+
):
8186
return c
8287
return 'Pending' if has_empty_grid else 'Draw'
8388
```

lcci/16.04.Tic-Tac-Toe/README_EN.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ class Solution:
8585
dg += v
8686
if i + j + 1 == n:
8787
udg += v
88-
if abs(rows[i]) == n or abs(cols[j]) == n or abs(dg) == n or abs(udg) == n:
88+
if (
89+
abs(rows[i]) == n
90+
or abs(cols[j]) == n
91+
or abs(dg) == n
92+
or abs(udg) == n
93+
):
8994
return c
9095
return 'Pending' if has_empty_grid else 'Draw'
9196
```

solution/0000-0099/0002.Add Two Numbers/Solution.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ function addTwoNumbers($l1, $l2) {
4444

4545
return $dummy->next;
4646
}
47-
}
47+
}

solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ function lengthOfLongestSubstring($s) {
2121
}
2222
return $max;
2323
}
24-
}
24+
}

solution/0100-0199/0100.Same Tree/Solution.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ function isSameTree($p, $q) {
2727
if ($p->val != $q->val) {
2828
return false;
2929
}
30-
return $this->isSameTree($p->left, $q->left) &&
31-
$this->isSameTree($p->right, $q->right);
30+
return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right);
3231
}
3332
}

solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public:
249249
for (int i = 0; i < n; ++i) {
250250
d[inOrder[i]].push_back(i);
251251
}
252-
function<vector<TreeNode*>(int, int, int)> dfs = [&](int i,int j, int n) -> vector<TreeNode*> {
252+
function<vector<TreeNode*>(int, int, int)> dfs = [&](int i, int j, int n) -> vector<TreeNode*> {
253253
vector<TreeNode*> ans;
254254
if (n <= 0) {
255255
ans.push_back(nullptr);

solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public:
239239
for (int i = 0; i < n; ++i) {
240240
d[inOrder[i]].push_back(i);
241241
}
242-
function<vector<TreeNode*>(int, int, int)> dfs = [&](int i,int j, int n) -> vector<TreeNode*> {
242+
function<vector<TreeNode*>(int, int, int)> dfs = [&](int i, int j, int n) -> vector<TreeNode*> {
243243
vector<TreeNode*> ans;
244244
if (n <= 0) {
245245
ans.push_back(nullptr);

solution/0100-0199/0175.Combine Two Tables/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def combine_two_tables(person: pd.DataFrame, address: pd.DataFrame) -> pd.DataFr
102102
return pd.merge(left=person, right=address, how="left", on="personId")[
103103
["firstName", "lastName", "city", "state"]
104104
]
105-
106105
```
107106

108107
<!-- tabs:end -->

solution/0100-0199/0181.Employees Earning More Than Their Managers/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def find_employees(employee: pd.DataFrame) -> pd.DataFrame:
8888
emp = df[df["salary_x"] > df["salary_y"]]["name_x"]
8989

9090
return pd.DataFrame({"Employee": emp})
91-
9291
```
9392

9493
<!-- tabs:end -->

solution/0100-0199/0185.Department Top Three Salaries/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ def top_three_salaries(
162162
return employee[employee["salary"] >= employee["cutoff"]].rename(
163163
columns={"name": "Employee", "salary": "Salary"}
164164
)[["Department", "Employee", "Salary"]]
165-
166165
```
167166

168167
<!-- tabs:end -->

solution/0100-0199/0185.Department Top Three Salaries/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ def top_three_salaries(
158158
return employee[employee["salary"] >= employee["cutoff"]].rename(
159159
columns={"name": "Employee", "salary": "Salary"}
160160
)[["Department", "Employee", "Salary"]]
161-
162161
```
163162

164163
<!-- tabs:end -->

solution/0100-0199/0196.Delete Duplicate Emails/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ def delete_duplicate_emails(person: pd.DataFrame) -> None:
109109
person.sort_values(by="id", ascending=True, inplace=True)
110110
# Drop the duplicates based on email.
111111
person.drop_duplicates(subset="email", keep="first", inplace=True)
112-
113112
```
114113

115114
<!-- tabs:end -->

solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ def delete_duplicate_emails(person: pd.DataFrame) -> None:
105105
person.sort_values(by="id", ascending=True, inplace=True)
106106
# Drop the duplicates based on email.
107107
person.drop_duplicates(subset="email", keep="first", inplace=True)
108-
109108
```
110109

111110
<!-- tabs:end -->

solution/0100-0199/0197.Rising Temperature/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def rising_temperature(weather: pd.DataFrame) -> pd.DataFrame:
9898
return weather[
9999
(weather.temperature.diff() > 0) & (weather.recordDate.diff().dt.days == 1)
100100
][["id"]]
101-
102101
```
103102

104103
<!-- tabs:end -->

solution/0100-0199/0197.Rising Temperature/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ def rising_temperature(weather: pd.DataFrame) -> pd.DataFrame:
9191
return weather[
9292
(weather.temperature.diff() > 0) & (weather.recordDate.diff().dt.days == 1)
9393
][["id"]]
94-
9594
```
9695

9796
<!-- tabs:end -->

solution/0200-0299/0219.Contains Duplicate II/Solution.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ function containsNearbyDuplicate($nums, $k) {
88
$hashtable = [];
99
for ($i = 0; $i < count($nums); $i++) {
1010
$tmp = $nums[$i];
11-
if (
12-
array_key_exists($tmp, $hashtable) &&
13-
$k >= $i - $hashtable[$tmp]
14-
) {
11+
if (array_key_exists($tmp, $hashtable) && $k >= $i - $hashtable[$tmp]) {
1512
return true;
1613
}
1714
$hashtable[$tmp] = $i;

solution/0200-0299/0262.Trips and Users/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ def trips_and_users(trips: pd.DataFrame, users: pd.DataFrame) -> pd.DataFrame:
186186
# 4) calculating the ratio
187187
df["Cancellation Rate"] = (df["total_cancelled"] / df["total"]).round(2)
188188
return df[["Day", "Cancellation Rate"]]
189-
190189
```
191190

192191
<!-- tabs:end -->

solution/0200-0299/0262.Trips and Users/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def trips_and_users(trips: pd.DataFrame, users: pd.DataFrame) -> pd.DataFrame:
173173
# 4) calculating the ratio
174174
df["Cancellation Rate"] = (df["total_cancelled"] / df["total"]).round(2)
175175
return df[["Day", "Cancellation Rate"]]
176-
177176
```
178177

179178
<!-- tabs:end -->

solution/0300-0399/0305.Number of Islands II/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ class Solution:
108108
cnt += 1
109109
for a, b in pairwise(dirs):
110110
x, y = i + a, j + b
111-
if 0 <= x < m and 0 <= y < n and grid[x][y] and uf.union(i * n + j, x * n + y):
111+
if (
112+
0 <= x < m
113+
and 0 <= y < n
114+
and grid[x][y]
115+
and uf.union(i * n + j, x * n + y)
116+
):
112117
cnt -= 1
113118
ans.append(cnt)
114119
return ans

solution/0300-0399/0305.Number of Islands II/README_EN.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@ class Solution:
100100
cnt += 1
101101
for a, b in pairwise(dirs):
102102
x, y = i + a, j + b
103-
if 0 <= x < m and 0 <= y < n and grid[x][y] and uf.union(i * n + j, x * n + y):
103+
if (
104+
0 <= x < m
105+
and 0 <= y < n
106+
and grid[x][y]
107+
and uf.union(i * n + j, x * n + y)
108+
):
104109
cnt -= 1
105110
ans.append(cnt)
106111
return ans

solution/0300-0399/0307.Range Sum Query - Mutable/README.md

+52-53
Original file line numberDiff line numberDiff line change
@@ -559,91 +559,90 @@ func (t *NumArray) SumRange(left int, right int) int {
559559

560560
```go
561561
type Node struct {
562-
l, r, v int
562+
l, r, v int
563563
}
564564

565565
type SegmentTree struct {
566-
tr []Node
567-
nums []int
566+
tr []Node
567+
nums []int
568568
}
569569

570570
func newSegmentTree(nums []int) *SegmentTree {
571-
n := len(nums)
572-
tr := make([]Node, n<<2)
573-
for i := range tr {
574-
tr[i] = Node{}
575-
}
576-
tree := &SegmentTree{
577-
tr: tr,
578-
nums: nums,
579-
}
580-
tree.build(1, 1, n)
581-
return tree
571+
n := len(nums)
572+
tr := make([]Node, n<<2)
573+
for i := range tr {
574+
tr[i] = Node{}
575+
}
576+
tree := &SegmentTree{
577+
tr: tr,
578+
nums: nums,
579+
}
580+
tree.build(1, 1, n)
581+
return tree
582582
}
583583

584584
func (tree *SegmentTree) build(u, l, r int) {
585-
tree.tr[u].l, tree.tr[u].r = l, r
586-
if l == r {
587-
tree.tr[u].v = tree.nums[l-1]
588-
return
589-
}
590-
mid := (l + r) >> 1
591-
tree.build(u<<1, l, mid)
592-
tree.build(u<<1|1, mid+1, r)
593-
tree.pushup(u)
585+
tree.tr[u].l, tree.tr[u].r = l, r
586+
if l == r {
587+
tree.tr[u].v = tree.nums[l-1]
588+
return
589+
}
590+
mid := (l + r) >> 1
591+
tree.build(u<<1, l, mid)
592+
tree.build(u<<1|1, mid+1, r)
593+
tree.pushup(u)
594594
}
595595

596596
func (tree *SegmentTree) modify(u, x, v int) {
597-
if tree.tr[u].l == x && tree.tr[u].r == x {
598-
tree.tr[u].v = v
599-
return
600-
}
601-
mid := (tree.tr[u].l + tree.tr[u].r) >> 1
602-
if x <= mid {
603-
tree.modify(u<<1, x, v)
604-
} else {
605-
tree.modify(u<<1|1, x, v)
606-
}
607-
tree.pushup(u)
597+
if tree.tr[u].l == x && tree.tr[u].r == x {
598+
tree.tr[u].v = v
599+
return
600+
}
601+
mid := (tree.tr[u].l + tree.tr[u].r) >> 1
602+
if x <= mid {
603+
tree.modify(u<<1, x, v)
604+
} else {
605+
tree.modify(u<<1|1, x, v)
606+
}
607+
tree.pushup(u)
608608
}
609609

610610
func (tree *SegmentTree) query(u, l, r int) (v int) {
611-
if tree.tr[u].l >= l && tree.tr[u].r <= r {
612-
return tree.tr[u].v
613-
}
614-
mid := (tree.tr[u].l + tree.tr[u].r) >> 1
615-
if l <= mid {
616-
v += tree.query(u<<1, l, r)
617-
}
618-
if r > mid {
619-
v += tree.query(u<<1|1, l, r)
620-
}
621-
return v
611+
if tree.tr[u].l >= l && tree.tr[u].r <= r {
612+
return tree.tr[u].v
613+
}
614+
mid := (tree.tr[u].l + tree.tr[u].r) >> 1
615+
if l <= mid {
616+
v += tree.query(u<<1, l, r)
617+
}
618+
if r > mid {
619+
v += tree.query(u<<1|1, l, r)
620+
}
621+
return v
622622
}
623623

624624
func (tree *SegmentTree) pushup(u int) {
625-
tree.tr[u].v = tree.tr[u<<1].v + tree.tr[u<<1|1].v
625+
tree.tr[u].v = tree.tr[u<<1].v + tree.tr[u<<1|1].v
626626
}
627627

628628
type NumArray struct {
629-
tree *SegmentTree
629+
tree *SegmentTree
630630
}
631631

632632
func Constructor(nums []int) NumArray {
633-
return NumArray{
634-
tree: newSegmentTree(nums),
635-
}
633+
return NumArray{
634+
tree: newSegmentTree(nums),
635+
}
636636
}
637637

638638
func (this *NumArray) Update(index int, val int) {
639-
this.tree.modify(1, index+1, val)
639+
this.tree.modify(1, index+1, val)
640640
}
641641

642642
func (this *NumArray) SumRange(left int, right int) int {
643-
return this.tree.query(1, left+1, right+1)
643+
return this.tree.query(1, left+1, right+1)
644644
}
645645

646-
647646
/**
648647
* Your NumArray object will be instantiated and called as such:
649648
* obj := Constructor(nums);

0 commit comments

Comments
 (0)