Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
NoComments
leetcode
提交
6fe551fc
L
leetcode
项目概览
NoComments
/
leetcode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
leetcode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6fe551fc
编写于
1月 27, 2019
作者:
L
liu13
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
20190127
上级
897e00e4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
61 addition
and
0 deletion
+61
-0
code/lc108.java
code/lc108.java
+29
-0
code/lc91.java
code/lc91.java
+32
-0
未找到文件。
code/lc108.java
0 → 100644
浏览文件 @
6fe551fc
package
code
;
/*
* 108. Convert Sorted Array to Binary Search Tree
* 题意:将有序数组转换为二叉平衡树
* 难度:Easy
* 分类:Tree, Depth-first Search
* 思路:类似二分查找,每次把数组劈成两半
* Tips:Bingo!
*/
public
class
lc108
{
public
class
TreeNode
{
int
val
;
TreeNode
left
;
TreeNode
right
;
TreeNode
(
int
x
)
{
val
=
x
;
}
}
public
TreeNode
sortedArrayToBST
(
int
[]
nums
)
{
TreeNode
tn
=
helper
(
nums
,
0
,
nums
.
length
-
1
);
return
tn
;
}
public
TreeNode
helper
(
int
[]
nums
,
int
left
,
int
right
){
if
(
left
<
right
)
return
null
;
int
mid
=
(
left
+
right
)/
2
;
TreeNode
tn
=
new
TreeNode
(
nums
[
mid
]);
tn
.
left
=
helper
(
nums
,
left
,
mid
-
1
);
tn
.
right
=
helper
(
nums
,
mid
+
1
,
right
);
return
tn
;
}
}
code/lc91.java
0 → 100644
浏览文件 @
6fe551fc
package
code
;
/*
* 91. Decode Ways
* 题意:1~26代表了26个字母
* 难度:Medium
* 分类:String, Dynamic Programming
* 思路:动态规划,和上台阶问题很像
* Tips:Bingo!
*/
public
class
lc91
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
numDecodings
(
"99"
));
}
public
static
int
numDecodings
(
String
s
)
{
if
(
s
.
length
()==
0
)
return
0
;
int
[]
dp
=
new
int
[
s
.
length
()+
1
];
dp
[
0
]
=
1
;
int
ch
=
s
.
charAt
(
0
)-
'0'
;
if
(
ch
<
1
||
ch
>
9
)
return
0
;
//判断第一个字符是否符合规范
else
dp
[
1
]
=
1
;
for
(
int
i
=
2
;
i
<
s
.
length
()+
1
;
i
++)
{
int
a
=
s
.
charAt
(
i
-
2
)-
'0'
;
int
b
=
s
.
charAt
(
i
-
1
)-
'0'
;
if
(
(
a
*
10
+
b
)<=
26
&&
(
a
*
10
+
b
)>=
10
)
//可能存在两个字符10符合,但一个字符0不符合的情况,所以+=
dp
[
i
]
+=
dp
[
i
-
2
];
if
(
b
>
0
&&
b
<=
9
)
dp
[
i
]
+=
dp
[
i
-
1
];
if
(
dp
[
i
]==
0
)
return
0
;
//解析错误
}
return
dp
[
s
.
length
()];
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录