Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Cs Summary Reflection
提交
28977631
C
Cs Summary Reflection
项目概览
梦境迷离
/
Cs Summary Reflection
8 个月 前同步成功
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Cs Summary Reflection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
28977631
编写于
4月 02, 2021
作者:
P
poorguy-tech
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
temporarily saved (not finish)
上级
803a7fb9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
81 addition
and
0 deletion
+81
-0
scala-leetcode/src/main/scala/io/github/poorguy/OpenTheLock.scala
...etcode/src/main/scala/io/github/poorguy/OpenTheLock.scala
+57
-0
scala-leetcode/src/main/scala/io/github/poorguy/trait/Bfs_.scala
...eetcode/src/main/scala/io/github/poorguy/trait/Bfs_.scala
+8
-0
scala-leetcode/src/main/scala/io/github/poorguy/trait/Queue_.scala
...tcode/src/main/scala/io/github/poorguy/trait/Queue_.scala
+8
-0
scala-leetcode/src/main/scala/io/github/poorguy/trait/Stack_.scala
...tcode/src/main/scala/io/github/poorguy/trait/Stack_.scala
+8
-0
未找到文件。
scala-leetcode/src/main/scala/io/github/poorguy/OpenTheLock.scala
0 → 100644
浏览文件 @
28977631
package
io.github.poorguy
import
io.github.poorguy.
`trait`
.{
Bfs_
,
Queue_
}
import
scala.collection.mutable
object
OpenTheLock
extends
App
with
Queue_
with
Bfs_
{
def
openLock
(
deadends
:
Array
[
String
],
target
:
String
)
:
Int
=
{
val
origin
=
"0000"
if
(
origin
.
equals
(
target
))
{
return
0
}
val
deadSet
=
deadends
.
toSet
val
directions
=
List
.
range
(
0
,
8
)
var
depth
=
0
var
sameDepthCount
=
0
val
queue
=
mutable
.
Queue
[
String
](
"0000"
)
while
(
queue
.
nonEmpty
)
{
if
(
sameDepthCount
==
0
)
depth
=
depth
+
1
else
sameDepthCount
-=
1
val
value
=
queue
.
dequeue
()
for
(
direct
<-
directions
)
{
val
newVal
=
tune
(
value
,
deadSet
,
direct
)
if
(
deadSet
.
contains
(
newVal
))
{
}
else
if
(
newVal
.
equals
(
target
))
{
return
depth
}
else
{
queue
.
enqueue
(
newVal
)
sameDepthCount
=
sameDepthCount
+
1
}
}
}
-
1
}
def
tune
(
origin
:
String
,
deadSet
:
Set
[
String
],
direction
:
Int
)
:
String
=
{
val
upDown
=
if
(
direction
%
2
==
0
)
1
else
-
1
val
index
=
origin
.
length
()
-
1
-
direction
/
2
val
value
=
origin
.
charAt
(
index
).
toString
.
toInt
val
originChars
=
origin
.
toCharArray
if
(
upDown
>
0
&&
value
==
9
)
{
originChars
(
index
)
=
'0'
}
else
if
(
upDown
<
0
&&
value
==
0
)
{
originChars
(
index
)
=
'9'
}
else
{
originChars
(
index
)
=
(
value
+
upDown
).
toString
.
charAt
(
0
)
}
originChars
.
mkString
}
val
list
=
Array
(
"0201"
,
"0101"
,
"0102"
,
"1212"
,
"2002"
)
print
(
openLock
(
list
,
"0202"
))
}
scala-leetcode/src/main/scala/io/github/poorguy/trait/Bfs_.scala
0 → 100644
浏览文件 @
28977631
package
io.github.poorguy.
`trait`
/**
* solution with BFS algorithm
*/
trait
Bfs_
{
}
scala-leetcode/src/main/scala/io/github/poorguy/trait/Queue_.scala
0 → 100644
浏览文件 @
28977631
package
io.github.poorguy.
`trait`
/**
* Solution with Queue
*/
trait
Queue_
{
}
scala-leetcode/src/main/scala/io/github/poorguy/trait/Stack_.scala
0 → 100644
浏览文件 @
28977631
package
io.github.poorguy.
`trait`
/**
* Solution with Stack
*/
trait
Stack_
{
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录