Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Damon-Da
leetcode
提交
9e6859a6
L
leetcode
项目概览
Damon-Da
/
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,发现更多精彩内容 >>
提交
9e6859a6
编写于
5月 07, 2019
作者:
L
liu13
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
20190507
上级
15e0467a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
82 addition
and
1 deletion
+82
-1
code/lc343.java
code/lc343.java
+24
-0
code/lc685.java
code/lc685.java
+55
-0
readme.md
readme.md
+3
-1
未找到文件。
code/lc343.java
0 → 100644
浏览文件 @
9e6859a6
package
code
;
/*
* 343. Integer Break
* 题意:给定一个正整数,找出一组数字和为该数,且这组数的乘积最大
* 难度:Medium
* 分类:Math, Dynamic Programming
* 思路:能减3的减3,因为3得到的乘积最大
* Tips:
*/
public
class
lc343
{
public
int
integerBreak
(
int
n
)
{
if
(
n
==
2
)
return
1
;
if
(
n
==
3
)
return
2
;
return
helper
(
n
);
}
public
int
helper
(
int
n
){
if
(
n
==
2
)
return
2
;
if
(
n
==
3
)
return
3
;
if
(
n
==
4
)
return
4
;
if
(
n
==
5
)
return
6
;
else
return
helper
(
n
-
3
)*
3
;
}
}
code/lc685.java
0 → 100644
浏览文件 @
9e6859a6
package
code
;
/*
* 685. Redundant Connection II
* 题意:一个图,删掉一个边,使其成为一个根树
* 难度:Hard
* 分类:Tree, Depth-first Search, Union Find, Graph
* 思路:要把问题想清楚
* 判断是否有某个节点父节点有两个, 记为e1, e2
* 再判断是否有环
* 4中情况,分别想清楚返回什么
* 自己没想清楚两种情况的交叉,以为判断完第一步就可直接返回
* 如何判断有环,可以利用并查集的思想
* Tips:https://leetcode.com/problems/redundant-connection-ii/discuss/108045/C%2B%2BJava-Union-Find-with-explanation-O(n)
*/
public
class
lc685
{
public
int
[]
findRedundantDirectedConnection
(
int
[][]
edges
)
{
int
[]
can1
=
{-
1
,
-
1
};
int
[]
can2
=
{-
1
,
-
1
};
int
[]
parent
=
new
int
[
edges
.
length
+
1
];
for
(
int
i
=
0
;
i
<
edges
.
length
;
i
++)
{
if
(
parent
[
edges
[
i
][
1
]]
==
0
)
{
parent
[
edges
[
i
][
1
]]
=
edges
[
i
][
0
];
}
else
{
can2
=
new
int
[]
{
edges
[
i
][
0
],
edges
[
i
][
1
]};
can1
=
new
int
[]
{
parent
[
edges
[
i
][
1
]],
edges
[
i
][
1
]};
edges
[
i
][
1
]
=
0
;
}
}
for
(
int
i
=
0
;
i
<
edges
.
length
;
i
++)
{
parent
[
i
]
=
i
;
}
for
(
int
i
=
0
;
i
<
edges
.
length
;
i
++)
{
if
(
edges
[
i
][
1
]
==
0
)
{
continue
;
}
int
child
=
edges
[
i
][
1
],
father
=
edges
[
i
][
0
];
if
(
root
(
parent
,
father
)
==
child
)
{
//判断father的父节点是不是child
if
(
can1
[
0
]
==
-
1
)
{
return
edges
[
i
];
}
return
can1
;
}
parent
[
child
]
=
father
;
}
return
can2
;
}
int
root
(
int
[]
parent
,
int
i
)
{
while
(
i
!=
parent
[
i
])
{
//找到根为止
parent
[
i
]
=
parent
[
parent
[
i
]];
i
=
parent
[
i
];
}
return
i
;
}
}
readme.md
浏览文件 @
9e6859a6
...
...
@@ -190,7 +190,8 @@ LeetCode 指南
| 337
[
Java
](
./code/lc337.java
)
| 338
[
Java
](
./code/lc338.java
)
| 341
[
Java
](
./code/lc341.java
)
| 344
[
Java
](
./code/lc338.java
)
| 343
[
Java
](
./code/lc343.java
)
| 344
[
Java
](
./code/lc344.java
)
| 347
[
Java
](
./code/lc347.java
)
| 350
[
Java
](
./code/lc350.java
)
| 371
[
Java
](
./code/lc371.java
)
...
...
@@ -217,6 +218,7 @@ LeetCode 指南
| 617
[
Java
](
./code/lc617.java
)
| 621
[
Java
](
./code/lc621.java
)
| 647
[
Java
](
./code/lc647.java
)
| 685
[
Java
](
./code/lc685.java
)
| 714
[
Java
](
./code/lc714.java
)
| 746
[
Java
](
./code/lc746.java
)
| 771
[
Java
](
./code/lc771.java
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录