From 8e27191aec0f9c377fe79b61a1b6deffa2af5fe4 Mon Sep 17 00:00:00 2001
From: ZongqinWang <1722249371@qq.com>
Date: Sat, 18 Jun 2022 20:29:53 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200062.=E4=B8=8D?=
=?UTF-8?q?=E5=90=8C=E8=B7=AF=E5=BE=84.md=20Scala=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0062.不同路径.md | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/problems/0062.不同路径.md b/problems/0062.不同路径.md
index f59b7be8..cccda7f1 100644
--- a/problems/0062.不同路径.md
+++ b/problems/0062.不同路径.md
@@ -412,5 +412,21 @@ int uniquePaths(int m, int n){
}
```
+### Scala
+
+```scala
+object Solution {
+ def uniquePaths(m: Int, n: Int): Int = {
+ var dp = Array.ofDim[Int](m, n)
+ for (i <- 0 until m) dp(i)(0) = 1
+ for (j <- 1 until n) dp(0)(j) = 1
+ for (i <- 1 until m; j <- 1 until n) {
+ dp(i)(j) = dp(i - 1)(j) + dp(i)(j - 1)
+ }
+ dp(m - 1)(n - 1)
+ }
+}
+```
+
-----------------------
From a9de01b83c02ab57181b52df37f4252b5709772f Mon Sep 17 00:00:00 2001
From: ZongqinWang <1722249371@qq.com>
Date: Sat, 18 Jun 2022 20:49:46 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200063.=E4=B8=8D?=
=?UTF-8?q?=E5=90=8C=E8=B7=AF=E5=BE=84II.md=20Scala=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0063.不同路径II.md | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/problems/0063.不同路径II.md b/problems/0063.不同路径II.md
index 59c60156..88fce505 100644
--- a/problems/0063.不同路径II.md
+++ b/problems/0063.不同路径II.md
@@ -440,5 +440,37 @@ int uniquePathsWithObstacles(int** obstacleGrid, int obstacleGridSize, int* obst
}
```
+### Scala
+
+```scala
+object Solution {
+ import scala.util.control.Breaks._
+ def uniquePathsWithObstacles(obstacleGrid: Array[Array[Int]]): Int = {
+ var (m, n) = (obstacleGrid.length, obstacleGrid(0).length)
+ var dp = Array.ofDim[Int](m, n)
+
+ // 比如break、continue这些流程控制需要使用breakable
+ breakable(
+ for (i <- 0 until m) {
+ if (obstacleGrid(i)(0) != 1) dp(i)(0) = 1
+ else break()
+ }
+ )
+ breakable(
+ for (j <- 0 until n) {
+ if (obstacleGrid(0)(j) != 1) dp(0)(j) = 1
+ else break()
+ }
+ )
+
+ for (i <- 1 until m; j <- 1 until n; if obstacleGrid(i)(j) != 1) {
+ dp(i)(j) = dp(i - 1)(j) + dp(i)(j - 1)
+ }
+
+ dp(m - 1)(n - 1)
+ }
+}
+```
+
-----------------------