Skip to content

feat: update lc problems #2185

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 1 commit into from
Jan 6, 2024
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
7 changes: 6 additions & 1 deletion lcci/16.04.Tic-Tac-Toe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ class Solution:
dg += v
if i + j + 1 == n:
udg += v
if abs(rows[i]) == n or abs(cols[j]) == n or abs(dg) == n or abs(udg) == n:
if (
abs(rows[i]) == n
or abs(cols[j]) == n
or abs(dg) == n
or abs(udg) == n
):
return c
return 'Pending' if has_empty_grid else 'Draw'
```
Expand Down
7 changes: 6 additions & 1 deletion lcci/16.04.Tic-Tac-Toe/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ class Solution:
dg += v
if i + j + 1 == n:
udg += v
if abs(rows[i]) == n or abs(cols[j]) == n or abs(dg) == n or abs(udg) == n:
if (
abs(rows[i]) == n
or abs(cols[j]) == n
or abs(dg) == n
or abs(udg) == n
):
return c
return 'Pending' if has_empty_grid else 'Draw'
```
Expand Down
2 changes: 1 addition & 1 deletion solution/0000-0099/0002.Add Two Numbers/Solution.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ function addTwoNumbers($l1, $l2) {

return $dummy->next;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ function lengthOfLongestSubstring($s) {
}
return $max;
}
}
}
3 changes: 1 addition & 2 deletions solution/0100-0199/0100.Same Tree/Solution.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function isSameTree($p, $q) {
if ($p->val != $q->val) {
return false;
}
return $this->isSameTree($p->left, $q->left) &&
$this->isSameTree($p->right, $q->right);
return $this->isSameTree($p->left, $q->left) && $this->isSameTree($p->right, $q->right);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public:
for (int i = 0; i < n; ++i) {
d[inOrder[i]].push_back(i);
}
function<vector<TreeNode*>(int, int, int)> dfs = [&](int i,int j, int n) -> vector<TreeNode*> {
function<vector<TreeNode*>(int, int, int)> dfs = [&](int i, int j, int n) -> vector<TreeNode*> {
vector<TreeNode*> ans;
if (n <= 0) {
ans.push_back(nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public:
for (int i = 0; i < n; ++i) {
d[inOrder[i]].push_back(i);
}
function<vector<TreeNode*>(int, int, int)> dfs = [&](int i,int j, int n) -> vector<TreeNode*> {
function<vector<TreeNode*>(int, int, int)> dfs = [&](int i, int j, int n) -> vector<TreeNode*> {
vector<TreeNode*> ans;
if (n <= 0) {
ans.push_back(nullptr);
Expand Down
1 change: 0 additions & 1 deletion solution/0100-0199/0175.Combine Two Tables/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def combine_two_tables(person: pd.DataFrame, address: pd.DataFrame) -> pd.DataFr
return pd.merge(left=person, right=address, how="left", on="personId")[
["firstName", "lastName", "city", "state"]
]

```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def find_employees(employee: pd.DataFrame) -> pd.DataFrame:
emp = df[df["salary_x"] > df["salary_y"]]["name_x"]

return pd.DataFrame({"Employee": emp})

```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ def top_three_salaries(
return employee[employee["salary"] >= employee["cutoff"]].rename(
columns={"name": "Employee", "salary": "Salary"}
)[["Department", "Employee", "Salary"]]

```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ def top_three_salaries(
return employee[employee["salary"] >= employee["cutoff"]].rename(
columns={"name": "Employee", "salary": "Salary"}
)[["Department", "Employee", "Salary"]]

```

<!-- tabs:end -->
1 change: 0 additions & 1 deletion solution/0100-0199/0196.Delete Duplicate Emails/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def delete_duplicate_emails(person: pd.DataFrame) -> None:
person.sort_values(by="id", ascending=True, inplace=True)
# Drop the duplicates based on email.
person.drop_duplicates(subset="email", keep="first", inplace=True)

```

<!-- tabs:end -->
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def delete_duplicate_emails(person: pd.DataFrame) -> None:
person.sort_values(by="id", ascending=True, inplace=True)
# Drop the duplicates based on email.
person.drop_duplicates(subset="email", keep="first", inplace=True)

```

<!-- tabs:end -->
1 change: 0 additions & 1 deletion solution/0100-0199/0197.Rising Temperature/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ def rising_temperature(weather: pd.DataFrame) -> pd.DataFrame:
return weather[
(weather.temperature.diff() > 0) & (weather.recordDate.diff().dt.days == 1)
][["id"]]

```

<!-- tabs:end -->
1 change: 0 additions & 1 deletion solution/0100-0199/0197.Rising Temperature/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def rising_temperature(weather: pd.DataFrame) -> pd.DataFrame:
return weather[
(weather.temperature.diff() > 0) & (weather.recordDate.diff().dt.days == 1)
][["id"]]

```

<!-- tabs:end -->
5 changes: 1 addition & 4 deletions solution/0200-0299/0219.Contains Duplicate II/Solution.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ function containsNearbyDuplicate($nums, $k) {
$hashtable = [];
for ($i = 0; $i < count($nums); $i++) {
$tmp = $nums[$i];
if (
array_key_exists($tmp, $hashtable) &&
$k >= $i - $hashtable[$tmp]
) {
if (array_key_exists($tmp, $hashtable) && $k >= $i - $hashtable[$tmp]) {
return true;
}
$hashtable[$tmp] = $i;
Expand Down
1 change: 0 additions & 1 deletion solution/0200-0299/0262.Trips and Users/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ def trips_and_users(trips: pd.DataFrame, users: pd.DataFrame) -> pd.DataFrame:
# 4) calculating the ratio
df["Cancellation Rate"] = (df["total_cancelled"] / df["total"]).round(2)
return df[["Day", "Cancellation Rate"]]

```

<!-- tabs:end -->
1 change: 0 additions & 1 deletion solution/0200-0299/0262.Trips and Users/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ def trips_and_users(trips: pd.DataFrame, users: pd.DataFrame) -> pd.DataFrame:
# 4) calculating the ratio
df["Cancellation Rate"] = (df["total_cancelled"] / df["total"]).round(2)
return df[["Day", "Cancellation Rate"]]

```

<!-- tabs:end -->
7 changes: 6 additions & 1 deletion solution/0300-0399/0305.Number of Islands II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ class Solution:
cnt += 1
for a, b in pairwise(dirs):
x, y = i + a, j + b
if 0 <= x < m and 0 <= y < n and grid[x][y] and uf.union(i * n + j, x * n + y):
if (
0 <= x < m
and 0 <= y < n
and grid[x][y]
and uf.union(i * n + j, x * n + y)
):
cnt -= 1
ans.append(cnt)
return ans
Expand Down
7 changes: 6 additions & 1 deletion solution/0300-0399/0305.Number of Islands II/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ class Solution:
cnt += 1
for a, b in pairwise(dirs):
x, y = i + a, j + b
if 0 <= x < m and 0 <= y < n and grid[x][y] and uf.union(i * n + j, x * n + y):
if (
0 <= x < m
and 0 <= y < n
and grid[x][y]
and uf.union(i * n + j, x * n + y)
):
cnt -= 1
ans.append(cnt)
return ans
Expand Down
105 changes: 52 additions & 53 deletions solution/0300-0399/0307.Range Sum Query - Mutable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,91 +559,90 @@ func (t *NumArray) SumRange(left int, right int) int {

```go
type Node struct {
l, r, v int
l, r, v int
}

type SegmentTree struct {
tr []Node
nums []int
tr []Node
nums []int
}

func newSegmentTree(nums []int) *SegmentTree {
n := len(nums)
tr := make([]Node, n<<2)
for i := range tr {
tr[i] = Node{}
}
tree := &SegmentTree{
tr: tr,
nums: nums,
}
tree.build(1, 1, n)
return tree
n := len(nums)
tr := make([]Node, n<<2)
for i := range tr {
tr[i] = Node{}
}
tree := &SegmentTree{
tr: tr,
nums: nums,
}
tree.build(1, 1, n)
return tree
}

func (tree *SegmentTree) build(u, l, r int) {
tree.tr[u].l, tree.tr[u].r = l, r
if l == r {
tree.tr[u].v = tree.nums[l-1]
return
}
mid := (l + r) >> 1
tree.build(u<<1, l, mid)
tree.build(u<<1|1, mid+1, r)
tree.pushup(u)
tree.tr[u].l, tree.tr[u].r = l, r
if l == r {
tree.tr[u].v = tree.nums[l-1]
return
}
mid := (l + r) >> 1
tree.build(u<<1, l, mid)
tree.build(u<<1|1, mid+1, r)
tree.pushup(u)
}

func (tree *SegmentTree) modify(u, x, v int) {
if tree.tr[u].l == x && tree.tr[u].r == x {
tree.tr[u].v = v
return
}
mid := (tree.tr[u].l + tree.tr[u].r) >> 1
if x <= mid {
tree.modify(u<<1, x, v)
} else {
tree.modify(u<<1|1, x, v)
}
tree.pushup(u)
if tree.tr[u].l == x && tree.tr[u].r == x {
tree.tr[u].v = v
return
}
mid := (tree.tr[u].l + tree.tr[u].r) >> 1
if x <= mid {
tree.modify(u<<1, x, v)
} else {
tree.modify(u<<1|1, x, v)
}
tree.pushup(u)
}

func (tree *SegmentTree) query(u, l, r int) (v int) {
if tree.tr[u].l >= l && tree.tr[u].r <= r {
return tree.tr[u].v
}
mid := (tree.tr[u].l + tree.tr[u].r) >> 1
if l <= mid {
v += tree.query(u<<1, l, r)
}
if r > mid {
v += tree.query(u<<1|1, l, r)
}
return v
if tree.tr[u].l >= l && tree.tr[u].r <= r {
return tree.tr[u].v
}
mid := (tree.tr[u].l + tree.tr[u].r) >> 1
if l <= mid {
v += tree.query(u<<1, l, r)
}
if r > mid {
v += tree.query(u<<1|1, l, r)
}
return v
}

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

type NumArray struct {
tree *SegmentTree
tree *SegmentTree
}

func Constructor(nums []int) NumArray {
return NumArray{
tree: newSegmentTree(nums),
}
return NumArray{
tree: newSegmentTree(nums),
}
}

func (this *NumArray) Update(index int, val int) {
this.tree.modify(1, index+1, val)
this.tree.modify(1, index+1, val)
}

func (this *NumArray) SumRange(left int, right int) int {
return this.tree.query(1, left+1, right+1)
return this.tree.query(1, left+1, right+1)
}


/**
* Your NumArray object will be instantiated and called as such:
* obj := Constructor(nums);
Expand Down
Loading