From a8cfc460e7143e6b6d8486ad9e8d88e1c9759211 Mon Sep 17 00:00:00 2001
From: ZongqinWang <1722249371@qq.com>
Date: 2022年5月11日 17:37:12 +0800
Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200059.=E8=9E=BA?=
=?UTF-8?q?=E6=97=8B=E7=9F=A9=E9=98=B5II.md=20Scala=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
...346円227円213円347円237円251円351円230円265円II.md" | 53 ++++++++++++++++++-
1 file changed, 52 insertions(+), 1 deletion(-)
diff --git "a/problems/0059.350円236円272円346円227円213円347円237円251円351円230円265円II.md" "b/problems/0059.350円236円272円346円227円213円347円237円251円351円230円265円II.md"
index a7b19a34fe..f3b8e1ce24 100644
--- "a/problems/0059.350円236円272円346円227円213円347円237円251円351円230円265円II.md"
+++ "b/problems/0059.350円236円272円346円227円213円347円237円251円351円230円265円II.md"
@@ -564,6 +564,57 @@ int** generateMatrix(int n, int* returnSize, int** returnColumnSizes){
return ans;
}
```
-
+Scala:
+```scala
+object Solution {
+ def generateMatrix(n: Int): Array[Array[Int]] = {
+ var res = Array.ofDim[Int](n, n) // 定义一个n*n的二维矩阵
+ var num = 1 // 标志当前到了哪个数字
+ var i = 0 // 横坐标
+ var j = 0 // 竖坐标
+
+ while (num <= n * n) { + // 向右:当j不越界,并且下一个要填的数字是空白时 + while (j < n && res(i)(j) == 0) { + res(i)(j) = num // 当前坐标等于num + num += 1 // num++ + j += 1 // 竖坐标+1 + } + i += 1 // 下移一行 + j -= 1 // 左移一列 + + // 剩下的都同上 + + // 向下 + while (i < n && res(i)(j) == 0) { + res(i)(j) = num + num += 1 + i += 1 + } + i -= 1 + j -= 1 + + // 向左 + while (j>= 0 && res(i)(j) == 0) {
+ res(i)(j) = num
+ num += 1
+ j -= 1
+ }
+ i -= 1
+ j += 1
+
+ // 向上
+ while (i>= 0 && res(i)(j) == 0) {
+ res(i)(j) = num
+ num += 1
+ i -= 1
+ }
+ i += 1
+ j += 1
+ }
+ res
+ }
+}
+```
-----------------------
From 558dc3343150b1a91a1f307c0bb1fcb881abcd20 Mon Sep 17 00:00:00 2001
From: ZongqinWang <1722249371@qq.com>
Date: 2022年5月11日 19:11:53 +0800
Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E9=93=BE=E8=A1=A8?=
=?UTF-8?q?=E7=90=86=E8=AE=BA=E5=9F=BA=E7=A1=80.md=20Scala=E7=89=88?=
=?UTF-8?q?=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
...250347円220円206円350円256円272円345円237円272円347円241円200円.md" | 7 +++++++
1 file changed, 7 insertions(+)
diff --git "a/problems/351円223円276円350円241円250円347円220円206円350円256円272円345円237円272円347円241円200円.md" "b/problems/351円223円276円350円241円250円347円220円206円350円256円272円345円237円272円347円241円200円.md"
index 095282f54f..9dddf1e232 100644
--- "a/problems/351円223円276円350円241円250円347円220円206円350円256円272円345円237円272円347円241円200円.md"
+++ "b/problems/351円223円276円350円241円250円347円220円206円350円256円272円345円237円272円347円241円200円.md"
@@ -210,6 +210,13 @@ type ListNode struct {
}
```
+Scala:
+```scala
+class ListNode(_x: Int = 0, _next: ListNode = null) {
+ var next: ListNode = _next
+ var x: Int = _x
+}
+```
-----------------------
From ef8564a5930805ace91776c5648fa7110800c2d7 Mon Sep 17 00:00:00 2001
From: ZongqinWang <1722249371@qq.com>
Date: 2022年5月11日 19:51:07 +0800
Subject: [PATCH 3/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200203.=E7=A7=BB?=
=?UTF-8?q?=E9=99=A4=E9=93=BE=E8=A1=A8=E5=85=83=E7=B4=A0.md=20Scala?=
=?UTF-8?q?=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
...76350円241円250円345円205円203円347円264円240円.md" | 32 ++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git "a/problems/0203.347円247円273円351円231円244円351円223円276円350円241円250円345円205円203円347円264円240円.md" "b/problems/0203.347円247円273円351円231円244円351円223円276円350円241円250円345円205円203円347円264円240円.md"
index c34831b768..53230c0b6c 100644
--- "a/problems/0203.347円247円273円351円231円244円351円223円276円350円241円250円345円205円203円347円264円240円.md"
+++ "b/problems/0203.347円247円273円351円231円244円351円223円276円350円241円250円345円205円203円347円264円240円.md"
@@ -446,6 +446,36 @@ impl Solution {
}
}
```
-
+Scala:
+```scala
+/**
+ * Definition for singly-linked list.
+ * class ListNode(_x: Int = 0, _next: ListNode = null) {
+ * var next: ListNode = _next
+ * var x: Int = _x
+ * }
+ */
+object Solution {
+ def removeElements(head: ListNode, `val`: Int): ListNode = {
+ if (head == null) return head
+ var dummy = new ListNode(-1, head) // 定义虚拟头节点
+ var cur = head // cur 表示当前节点
+ var pre = dummy // pre 表示cur前一个节点
+ while (cur != null) {
+ if (cur.x == `val`) {
+ // 相等,就删除那么cur的前一个节点pre执行cur的下一个
+ pre.next = cur.next
+ } else {
+ // 不相等,pre就等于当前cur节点
+ pre = cur
+ }
+ // 向下迭代
+ cur = cur.next
+ }
+ // 最终返回dummy的下一个,就是链表的头
+ dummy.next
+ }
+}
+```
-----------------------
From 923ce563f1461876fbed667f8a79194ccb060096 Mon Sep 17 00:00:00 2001
From: yangtzech
Date: 2022年5月11日 21:30:43 +0800
Subject: [PATCH 4/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=EF=BC=880102.?=
=?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=A0=91=E7=9A=84=E5=B1=82=E5=BA=8F=E9=81=8D?=
=?UTF-8?q?=E5=8E=86.md=EF=BC=89=EF=BC=9A102.=E4=BA=8C=E5=8F=89=E6=A0=91?=
=?UTF-8?q?=E7=9A=84=E5=B1=82=E5=BA=8F=E9=81=8D=E5=8E=86=20=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0=20c++=20=E9=80=92=E5=BD=92=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
...02345円272円217円351円201円215円345円216円206円.md" | 20 +++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git "a/problems/0102.344円272円214円345円217円211円346円240円221円347円232円204円345円261円202円345円272円217円351円201円215円345円216円206円.md" "b/problems/0102.344円272円214円345円217円211円346円240円221円347円232円204円345円261円202円345円272円217円351円201円215円345円216円206円.md"
index ab8f2e572e..5f69f53d76 100644
--- "a/problems/0102.344円272円214円345円217円211円346円240円221円347円232円204円345円261円202円345円272円217円351円201円215円345円216円206円.md"
+++ "b/problems/0102.344円272円214円345円217円211円346円240円221円347円232円204円345円261円202円345円272円217円351円201円215円345円216円206円.md"
@@ -82,6 +82,26 @@ public:
}
};
```
+```CPP
+# 递归法
+class Solution {
+public:
+ void order(TreeNode* cur, vector>& result, int depth)
+ {
+ if (cur == nullptr) return;
+ if (result.size() == depth) result.push_back(vector());
+ result[depth].push_back(cur->val);
+ order(cur->left, result, depth + 1);
+ order(cur->right, result, depth + 1);
+ }
+ vector> levelOrder(TreeNode* root) {
+ vector> result;
+ int depth = 0;
+ order(root, result, depth);
+ return result;
+ }
+};
+```
python3代码: