Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Cs Summary Reflection
提交
4256c75a
C
Cs Summary Reflection
项目概览
梦境迷离
/
Cs Summary Reflection
10 个月 前同步成功
通知
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 搜索 >>
提交
4256c75a
编写于
8月 11, 2020
作者:
梦境迷离
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:jxnu-liguobin/cs-summary-reflection
上级
ddab9554
51151a6b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
96 addition
and
1 deletion
+96
-1
scala-leetcode/src/main/scala/io/github/sweeneycai/Leetcode_130.scala
...de/src/main/scala/io/github/sweeneycai/Leetcode_130.scala
+57
-0
scala-leetcode/src/main/scala/io/github/sweeneycai/Leetcode_696.scala
...de/src/main/scala/io/github/sweeneycai/Leetcode_696.scala
+37
-0
scala-leetcode/src/main/scala/io/github/sweeneycai/sweeneycai.md
...eetcode/src/main/scala/io/github/sweeneycai/sweeneycai.md
+2
-1
未找到文件。
scala-leetcode/src/main/scala/io/github/sweeneycai/Leetcode_130.scala
0 → 100644
浏览文件 @
4256c75a
/* Licensed under Apache-2.0 (C) All Contributors */
package
io.github.sweeneycai
/**
* 130. 被围绕的区域 (Medium)
*
* 给定一个二维的矩阵,包含 'X' 和 'O'(字母 O)。
*
* 找到所有被 'X' 围绕的区域,并将这些区域里所有的 'O' 用 'X' 填充。
*/
object
Leetcode_130
extends
App
{
/**
* 典型的深度优先搜索题目。可以从矩阵四周查找所有有关联的 'O' ,然后
* 再修改矩阵内部所有孤立的 'O' 。
*/
def
solve
(
board
:
Array
[
Array
[
Char
]])
:
Unit
=
{
if
(
board
.
isEmpty
)
return
val
L
=
board
.
length
val
W
=
board
(
0
).
length
var
set
:
Set
[(
Int
,
Int
)]
=
Set
.
empty
def
recur
(
i
:
Int
,
j
:
Int
)
:
Unit
=
{
if
(
i
<
0
||
i
>=
L
||
j
<
0
||
j
>=
W
||
set
.
contains
((
i
,
j
))
||
board
(
i
)(
j
)
!=
'O'
)
return
set
=
set
+
(
i
->
j
)
recur
(
i
-
1
,
j
)
recur
(
i
+
1
,
j
)
recur
(
i
,
j
-
1
)
recur
(
i
,
j
+
1
)
}
for
(
i
<-
0
until
L
)
{
if
(
board
(
i
)(
0
)
==
'O'
)
recur
(
i
,
0
)
if
(
board
(
i
)(
W
-
1
)
==
'O'
)
recur
(
i
,
W
-
1
)
}
for
(
j
<-
0
until
W
)
{
if
(
board
(
0
)(
j
)
==
'O'
)
recur
(
0
,
j
)
if
(
board
(
L
-
1
)(
j
)
==
'O'
)
recur
(
L
-
1
,
j
)
}
for
(
i
<-
0
until
L
;
j
<-
0
until
W
)
{
if
(
board
(
i
)(
j
)
==
'O'
&&
!
set
.
contains
((
i
,
j
)))
board
(
i
)(
j
)
=
'X'
}
}
val
array
=
Array
(
Array
(
'X'
,
'X'
,
'X'
,
'X'
),
Array
(
'X'
,
'O'
,
'O'
,
'X'
),
Array
(
'X'
,
'X'
,
'O'
,
'X'
),
Array
(
'X'
,
'O'
,
'X'
,
'X'
)
)
solve
(
array
)
println
(
array
.
map
(
_
.
mkString
(
"Array("
,
", "
,
")"
)).
mkString
(
"Array(\n"
,
"\n"
,
"\n)"
))
}
scala-leetcode/src/main/scala/io/github/sweeneycai/Leetcode_696.scala
0 → 100644
浏览文件 @
4256c75a
/* Licensed under Apache-2.0 (C) All Contributors */
package
io.github.sweeneycai
/**
* 696. 计数二进制子串 (Easy)
* 给定一个字符串s,计算具有相同数量0和1的非空(连续)子字符串的数量,
* 并且这些子字符串中的所有0和所有1都是组合在一起的。
*
* 重复出现的子串要计算它们出现的次数。
*/
object
Leetcode_696
extends
App
{
def
countBinarySubstrings
(
s
:
String
)
:
Int
=
{
if
(
s
.
length
==
0
)
{
return
1
}
// 使用`foldLeft`对输入的字符串进行分割,将0和1区分开。
val
splitUsingFold
=
s
.
foldLeft
(
Array
[
String
]())
{
(
string
,
char
)
=>
if
(
string
.
isEmpty
)
string
:+
char
.
toString
else
{
if
(
string
(
string
.
length
-
1
).
charAt
(
0
)
==
char
)
{
string
(
string
.
length
-
1
)
+=
char
string
}
else
{
string
:+
char
.
toString
}
}
}
var
res
=
0
for
(
i
<-
splitUsingFold
.
indices
.
drop
(
1
))
{
res
+=
math
.
min
(
splitUsingFold
(
i
).
length
,
splitUsingFold
(
i
-
1
).
length
)
}
res
}
println
(
countBinarySubstrings
(
"1010100111100111"
))
}
scala-leetcode/src/main/scala/io/github/sweeneycai/sweeneycai.md
浏览文件 @
4256c75a
...
...
@@ -10,8 +10,9 @@
-
[
365.水壶问题
](
./Leetcode_365.scala
)
-
[
93. 复原IP地址
](
./Leetcode_93.scala
)
-
[
130. 被围绕的区域
](
./Leetcode_130.scala
)
### 其他
-
[
415.字符串相加
](
./Leetcode_415.scala
)
-
[
696. 计数二进制子串
](
./Leetcode_696.scala
)
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录