Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
NoComments
leetcode
提交
f6df74a7
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,发现更多精彩内容 >>
提交
f6df74a7
编写于
3月 15, 2019
作者:
L
liu13
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
20190315
上级
dc318574
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
2 deletion
+44
-2
code/lc113.java
code/lc113.java
+39
-0
code/lc31.java
code/lc31.java
+1
-1
code/lc49.java
code/lc49.java
+1
-1
readme.md
readme.md
+3
-0
未找到文件。
code/lc113.java
0 → 100644
浏览文件 @
f6df74a7
package
code
;
import
java.util.ArrayList
;
import
java.util.List
;
/*
* 113. Path Sum II
* 题意:找从root到叶子节点和为sum的路径
* 难度:Medium
* 分类:Tree, Depth-first Search
* 思路:回溯,注意因为节点上可能正值,可能负值,所以不能剪枝
* Tips:
*/
public
class
lc113
{
public
class
TreeNode
{
int
val
;
TreeNode
left
;
TreeNode
right
;
TreeNode
(
int
x
)
{
val
=
x
;
}
}
public
List
<
List
<
Integer
>>
pathSum
(
TreeNode
root
,
int
sum
)
{
List
<
List
<
Integer
>>
res
=
new
ArrayList
<>();
helper
(
res
,
root
,
sum
,
0
,
new
ArrayList
<>());
return
res
;
}
public
void
helper
(
List
<
List
<
Integer
>>
res
,
TreeNode
root
,
int
sum
,
int
curr
,
List
<
Integer
>
curr_ls
)
{
if
(
root
==
null
)
return
;
curr_ls
.
add
(
root
.
val
);
if
(
curr
+
root
.
val
==
sum
&&
root
.
left
==
null
&&
root
.
right
==
null
)
{
//到叶子节点
res
.
add
(
new
ArrayList
<>(
curr_ls
));
curr_ls
.
remove
(
curr_ls
.
size
()-
1
);
return
;
}
helper
(
res
,
root
.
left
,
sum
,
curr
+
root
.
val
,
curr_ls
);
helper
(
res
,
root
.
right
,
sum
,
curr
+
root
.
val
,
curr_ls
);
curr_ls
.
remove
(
curr_ls
.
size
()-
1
);
}
}
code/lc31.java
浏览文件 @
f6df74a7
...
...
@@ -28,7 +28,7 @@ public class lc31 {
//从这个数之后的数中找出第一个比x大的数
int
n
=
nums
[
ptr
];
int
ptr2
=
ptr
;
for
(
int
i
=
ptr
+
1
;
i
<
nums
.
length
;
i
++){
for
(
int
i
=
ptr
+
1
;
i
<
nums
.
length
;
i
++){
//这不用这么麻烦,后边的数有序的,这可以简化
if
(
nums
[
i
]>
nums
[
ptr
-
1
]
&&
nums
[
i
]<=
n
)
{
//注意 <= {2,3,1,3,3}
n
=
nums
[
i
];
ptr2
=
i
;
...
...
code/lc49.java
浏览文件 @
f6df74a7
...
...
@@ -14,7 +14,7 @@ public class lc49 {
HashMap
<
String
,
List
<
String
>>
m
=
new
HashMap
();
for
(
int
i
=
0
;
i
<
strs
.
length
;
i
++)
{
char
[]
chs
=
strs
[
i
].
toCharArray
();
Arrays
.
sort
(
chs
);
Arrays
.
sort
(
chs
);
//对字符串排序
String
key
=
String
.
valueOf
(
chs
);
if
(
m
.
containsKey
(
key
))
m
.
get
(
key
).
add
(
strs
[
i
]);
...
...
readme.md
浏览文件 @
f6df74a7
...
...
@@ -89,15 +89,18 @@ LeetCode 指南
| 095
[
Java
](
./code/lc95.java
)
| 096
[
Java
](
./code/lc96.java
)
| 098
[
Java
](
./code/lc98.java
)
| 100
[
Java
](
./code/lc100.java
)
| 101
[
Java
](
./code/lc101.java
)
| 102
[
Java
](
./code/lc102.java
)
| 103
[
Java
](
./code/lc103.java
)
| 104
[
Java
](
./code/lc104.java
)
| 105
[
Java
](
./code/lc105.java
)
| 108
[
Java
](
./code/lc108.java
)
| 113
[
Java
](
./code/lc113.java
)
| 114
[
Java
](
./code/lc114.java
)
| 116
[
Java
](
./code/lc116.java
)
| 118
[
Java
](
./code/lc118.java
)
| 119
[
Java
](
./code/lc119.java
)
| 120
[
Java
](
./code/lc120.java
)
| 121
[
Java
](
./code/lc121.java
)
| 122
[
Java
](
./code/lc122.java
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录