Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
java-data-algorithm
提交
d3fec083
J
java-data-algorithm
项目概览
门心叼龙
/
java-data-algorithm
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
java-data-algorithm
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d3fec083
编写于
9月 01, 2019
作者:
门心叼龙
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code perfect
上级
0c665e91
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
428 addition
and
1 deletion
+428
-1
.idea/misc.xml
.idea/misc.xml
+1
-1
testlib/src/main/java/I2019/A003/ReView03ListNode.java
testlib/src/main/java/I2019/A003/ReView03ListNode.java
+180
-0
testlib/src/main/java/I2019/A003/ReView04TreeNode.java
testlib/src/main/java/I2019/A003/ReView04TreeNode.java
+105
-0
testlib/src/main/java/I2019/A003/ReView05Int.java
testlib/src/main/java/I2019/A003/ReView05Int.java
+34
-0
testlib/src/main/java/I2019/A003/ReView06String.java
testlib/src/main/java/I2019/A003/ReView06String.java
+90
-0
testlib/src/main/java/I2019/A003/TreeNode.java
testlib/src/main/java/I2019/A003/TreeNode.java
+18
-0
未找到文件。
.idea/misc.xml
浏览文件 @
d3fec083
...
...
@@ -35,7 +35,7 @@
</value>
</option>
</component>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
7
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<component
name=
"ProjectRootManager"
version=
"2"
languageLevel=
"JDK_1_
8
"
project-jdk-name=
"1.8"
project-jdk-type=
"JavaSDK"
>
<output
url=
"file://$PROJECT_DIR$/build/classes"
/>
</component>
<component
name=
"ProjectType"
>
...
...
testlib/src/main/java/I2019/A003/ReView03ListNode.java
0 → 100644
浏览文件 @
d3fec083
package
I2019.A003
;
/**
* Description: <ReView03ListNode><br>
* Author: mxdl<br>
* Date: 2019/9/1<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public
class
ReView03ListNode
{
//1.判断一个链表有没有后环
public
static
boolean
isRingListNode
(
ListNode
listNode
)
{
ListNode
slow
=
listNode
;
ListNode
fast
=
listNode
;
while
(
fast
!=
null
&&
fast
.
next
!=
null
)
{
//*****
slow
=
slow
.
next
;
fast
=
fast
.
next
.
next
;
if
(
slow
==
fast
)
{
return
true
;
}
}
return
false
;
}
//2.找到链表的入口节点
public
static
ListNode
getEnterRingListNode
(
ListNode
listNode
)
{
ListNode
slow
=
listNode
;
ListNode
fast
=
listNode
;
boolean
isRing
=
false
;
while
(
fast
!=
null
&&
fast
.
next
!=
null
)
{
slow
=
slow
.
next
;
fast
=
fast
.
next
.
next
;
if
(
slow
==
fast
)
{
isRing
=
true
;
break
;
}
}
if
(!
isRing
)
{
return
null
;
//*****
}
fast
=
listNode
;
while
(
slow
!=
fast
)
{
slow
=
slow
.
next
;
fast
=
fast
.
next
;
}
return
slow
;
}
//3.翻转一个链表
public
static
ListNode
revertListNode
(
ListNode
listNode
)
{
ListNode
currNode
=
listNode
;
ListNode
preNode
=
null
;
ListNode
headNode
=
null
;
while
(
currNode
!=
null
)
{
ListNode
nextNode
=
currNode
.
next
;
//*****
if
(
nextNode
==
null
)
{
headNode
=
currNode
;
}
currNode
.
next
=
preNode
;
preNode
=
currNode
;
currNode
=
nextNode
;
}
return
headNode
;
}
//4.删除链表的倒数第n个节点
public
static
ListNode
removeListNodeByN
(
ListNode
listNode
,
int
n
)
{
ListNode
pa
=
listNode
;
int
i
=
0
;
while
(
i
<
n
)
{
pa
=
pa
.
next
;
i
++;
}
if
(
pa
==
null
)
{
return
listNode
.
next
;
}
ListNode
pb
=
listNode
;
while
(
pa
.
next
!=
null
)
{
//*****
pa
=
pa
.
next
;
pb
=
pb
.
next
;
}
pb
.
next
=
pb
.
next
.
next
;
return
listNode
;
}
//5.合并两个有序链表
public
static
ListNode
mergeTwoListNode
(
ListNode
pa
,
ListNode
pb
)
{
ListNode
listNode
=
new
ListNode
(-
1
);
ListNode
headNode
=
listNode
;
//*****
while
(
pa
!=
null
&&
pb
!=
null
)
{
if
(
pa
.
val
<
pb
.
val
)
{
listNode
.
next
=
pa
;
pa
=
pa
.
next
;
}
else
{
listNode
.
next
=
pb
;
pb
=
pb
.
next
;
}
listNode
=
listNode
.
next
;
}
listNode
.
next
=
pa
!=
null
?
pa
:
pb
;
//*****
return
headNode
.
next
;
}
//6.两个链表求和
public
static
ListNode
sumTowListNode
(
ListNode
pa
,
ListNode
pb
){
ListNode
currNode
=
new
ListNode
(-
1
);
ListNode
headNode
=
currNode
;
int
carry
=
0
;
while
(
pa
!=
null
&&
pb
!=
null
){
int
sum
=
carry
+
pa
.
val
+
pb
.
val
;
currNode
.
next
=
new
ListNode
(
sum
%
10
);
carry
=
sum
/
10
;
pa
=
pa
.
next
;
pb
=
pb
.
next
;
currNode
=
currNode
.
next
;
}
if
(
carry
>
0
){
currNode
.
next
=
new
ListNode
(
carry
);
}
return
headNode
.
next
;
}
public
static
ListNode
mergeListNode1
(
ListNode
pa
,
ListNode
pb
)
{
ListNode
currNode
=
new
ListNode
(-
1
);
ListNode
headNode
=
currNode
;
while
(
pa
!=
null
&&
pb
!=
null
)
{
if
(
pa
.
val
<
pb
.
val
)
{
currNode
.
next
=
pa
;
pa
=
pa
.
next
;
}
else
{
currNode
.
next
=
pb
;
pb
=
pb
.
next
;
}
currNode
=
currNode
.
next
;
}
currNode
.
next
=
pa
!=
null
?
pa
:
pb
;
return
headNode
.
next
;
}
public
static
void
main
(
String
[]
args
)
{
// ListNode listNode = new ListNode(0);
// ListNode listNode1 = new ListNode(1);
// ListNode listNode2 = new ListNode(2);
// ListNode listNode3 = new ListNode(3);
//
// listNode.next = listNode1;
// listNode1.next = listNode2;
// listNode2.next = listNode3;
//listNode3.next = listNode2;
//boolean cricleListNode = isRingListNode(listNode);
//System.out.println(cricleListNode);
//ListNode enterRingListNode = getEnterRingListNode(listNode);
//System.out.println(enterRingListNode.val);
// ListNode listNode4 = revertListNode(listNode);
// ListNode listNode4 = removeListNodeByN(listNode, 1);
// while (listNode4 != null) {
// System.out.println(listNode4.val);
// listNode4 = listNode4.next;
// }
ListNode
listNodea
=
new
ListNode
(
1
);
ListNode
listNode1a
=
new
ListNode
(
3
);
ListNode
listNode2a
=
new
ListNode
(
5
);
listNodea
.
next
=
listNode1a
;
listNode1a
.
next
=
listNode2a
;
ListNode
listNodeaa
=
new
ListNode
(
2
);
ListNode
listNode1aa
=
new
ListNode
(
4
);
ListNode
listNode2aa
=
new
ListNode
(
6
);
//ListNode listNode2aaa = new ListNode(7);
listNodeaa
.
next
=
listNode1aa
;
listNode1aa
.
next
=
listNode2aa
;
//listNode2aa.next = listNode2aaa;
ListNode
listNode4
=
sumTowListNode
(
listNodea
,
listNodeaa
);
while
(
listNode4
!=
null
)
{
System
.
out
.
println
(
listNode4
.
val
);
listNode4
=
listNode4
.
next
;
}
}
}
testlib/src/main/java/I2019/A003/ReView04TreeNode.java
0 → 100644
浏览文件 @
d3fec083
package
I2019.A003
;
/**
* Description: <ReView04TreeNode><br>
* Author: mxdl<br>
* Date: 2019/9/1<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public
class
ReView04TreeNode
{
//1.求二叉树的结点数
public
static
int
getTreeNodeCount
(
TreeNode
treeNode
)
{
if
(
treeNode
==
null
)
{
return
0
;
}
return
1
+
getTreeNodeCount
(
treeNode
.
leftNode
)
+
getTreeNodeCount
(
treeNode
.
rightNode
);
}
//2.求二叉树的高度
public
static
int
getTreeNodeHeight
(
TreeNode
treeNode
)
{
if
(
treeNode
==
null
)
{
return
0
;
}
int
leftHeight
=
1
+
getTreeNodeHeight
(
treeNode
.
leftNode
);
int
rightHeight
=
1
+
getTreeNodeHeight
(
treeNode
.
rightNode
);
return
Math
.
max
(
leftHeight
,
rightHeight
);
}
//3.中序遍历二叉树
public
static
void
printMiddleTreeNode
(
TreeNode
treeNode
)
{
if
(
treeNode
==
null
)
{
return
;
}
printMiddleTreeNode
(
treeNode
.
leftNode
);
System
.
out
.
println
(
treeNode
.
val
);
printMiddleTreeNode
(
treeNode
.
rightNode
);
}
//5.判断两个二叉树是否是完全二叉树
public
static
boolean
isEqualTreeNode
(
TreeNode
ta
,
TreeNode
tb
)
{
if
(
ta
==
null
&&
tb
==
null
)
{
return
true
;
}
if
(
ta
==
null
&&
tb
!=
null
)
{
return
false
;
}
if
(
ta
!=
null
&&
tb
==
null
)
{
return
false
;
}
return
ta
.
val
==
tb
.
val
&&
isEqualTreeNode
(
ta
.
leftNode
,
tb
.
leftNode
)
&&
isEqualTreeNode
(
ta
.
rightNode
,
tb
.
rightNode
);
}
//6.判断一个二叉树是否是对称二叉树
public
static
boolean
isSymsetry
(
TreeNode
treeNode
)
{
if
(
treeNode
==
null
)
{
return
false
;
}
else
{
return
isSymserty
(
treeNode
.
leftNode
,
treeNode
.
rightNode
);
}
}
public
static
boolean
isSymserty
(
TreeNode
leftNode
,
TreeNode
rightNode
)
{
if
(
leftNode
==
null
&&
rightNode
==
null
)
{
return
true
;
}
if
(
leftNode
!=
null
&&
rightNode
==
null
)
{
return
false
;
}
if
(
leftNode
==
null
&&
rightNode
!=
null
)
{
return
false
;
}
return
leftNode
.
val
==
rightNode
.
val
&&
isSymserty
(
leftNode
.
leftNode
,
rightNode
.
rightNode
)
&&
isSymserty
(
leftNode
.
rightNode
,
rightNode
.
leftNode
);
}
public
static
void
main
(
String
[]
args
)
{
TreeNode
treeNode
=
new
TreeNode
(
0
);
TreeNode
treeNode1
=
new
TreeNode
(
1
);
TreeNode
treeNode2
=
new
TreeNode
(
1
);
TreeNode
treeNode3
=
new
TreeNode
(
3
);
TreeNode
treeNode4
=
new
TreeNode
(
4
);
TreeNode
treeNode5
=
new
TreeNode
(
5
);
TreeNode
treeNode6
=
new
TreeNode
(
6
);
treeNode
.
leftNode
=
treeNode1
;
treeNode
.
rightNode
=
treeNode2
;
treeNode1
.
leftNode
=
treeNode3
;
treeNode2
.
rightNode
=
treeNode3
;
treeNode1
.
rightNode
=
treeNode4
;
treeNode2
.
leftNode
=
treeNode6
;
//treeNode1.leftNode = treeNode3;
//treeNode1.rightNode = treeNode4;
//treeNode2.leftNode = treeNode6;
//treeNode2.rightNode = treeNode5;
// int treeNodeCount = getTreeNodeCount(treeNode);
// System.out.println(treeNodeCount);
//int treeNodeHeight = getTreeNodeHeight(treeNode);
//System.out.println(treeNodeHeight);
//printMiddleTreeNode(treeNode);
boolean
equalTreeNode
=
isSymsetry
(
treeNode
);
System
.
out
.
println
(
equalTreeNode
);
}
}
testlib/src/main/java/I2019/A003/ReView05Int.java
0 → 100644
浏览文件 @
d3fec083
package
I2019.A003
;
/**
* Description: <ReView05Int><br>
* Author: mxdl<br>
* Date: 2019/9/1<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public
class
ReView05Int
{
//1.翻转一个整数
public
static
int
revertInt
(
int
num
)
{
int
result
=
0
;
while
(
num
>
0
)
{
result
=
result
*
10
+
num
%
10
;
num
=
num
/
10
;
}
return
result
;
}
public
static
void
main
(
String
[]
args
)
{
int
result
=
revertInt1
(
123
);
System
.
out
.
println
(
result
);
}
public
static
int
revertInt1
(
int
num
)
{
int
result
=
0
;
while
(
num
>
0
)
{
result
=
result
*
10
+
num
%
10
;
num
=
num
/
10
;
}
return
result
;
}
}
testlib/src/main/java/I2019/A003/ReView06String.java
0 → 100644
浏览文件 @
d3fec083
package
I2019.A003
;
/**
* Description: <ReView06String><br>
* Author: mxdl<br>
* Date: 2019/9/1<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public
class
ReView06String
{
//1.查找最大的非重复字符串
public
static
String
searchMaxStr
(
String
result
)
{
//String reg = "\\.(1)+";
String
reg1
=
"(.)\\1+"
;
//******************
String
[]
split
=
result
.
split
(
reg1
);
String
maxStr
=
""
;
for
(
String
str
:
split
)
{
if
(
str
.
length
()
>
maxStr
.
length
())
{
maxStr
=
str
;
}
}
return
maxStr
;
}
public
static
String
getLongText
(
String
str
)
{
boolean
[][]
arr
=
new
boolean
[
str
.
length
()][
str
.
length
()];
int
maxLen
=
0
;
String
longText
=
""
;
for
(
int
i
=
0
;
i
<
str
.
length
();
i
++)
{
arr
[
i
][
i
]
=
true
;
maxLen
=
1
;
}
for
(
int
i
=
0
;
i
<
str
.
length
()-
1
;
i
++)
{
//*****
if
(
str
.
charAt
(
i
)
==
str
.
charAt
(
i
+
1
))
{
arr
[
i
][
i
+
1
]
=
true
;
}
maxLen
=
2
;
}
for
(
int
len
=
3
;
len
<
str
.
length
();
len
++)
{
for
(
int
i
=
0
,
j
=
0
;
(
j
=
len
+
i
-
1
)
<
str
.
length
();
i
++)
{
//******
if
(
str
.
charAt
(
i
)
==
str
.
charAt
(
j
)){
arr
[
i
][
j
]
=
arr
[
i
+
1
][
j
-
1
];
if
(
arr
[
i
][
j
]
&&
maxLen
<
len
){
longText
=
str
.
substring
(
i
,
j
+
1
);
maxLen
=
len
;
}
}
else
{
arr
[
i
][
j
]
=
false
;
}
}
}
return
longText
;
}
public
static
String
getLongText1
(
String
str
){
boolean
[][]
arr
=
new
boolean
[
str
.
length
()][
str
.
length
()];
int
maxLen
=
0
;
String
longText
=
""
;
for
(
int
i
=
0
;
i
<
str
.
length
();
i
++){
arr
[
i
][
i
]
=
true
;
maxLen
=
1
;
}
for
(
int
i
=
0
;
i
<
str
.
length
()-
1
;
i
++){
if
(
str
.
charAt
(
i
)
==
str
.
charAt
(
i
+
1
)){
arr
[
i
][
i
+
1
]
=
true
;
maxLen
=
2
;
}
}
for
(
int
len
=
3
;
len
<
str
.
length
();
len
++){
for
(
int
i
=
0
,
j
=
0
;
(
j
=
len
+
i
-
1
)<
str
.
length
();
i
++){
if
(
str
.
charAt
(
i
)
==
str
.
charAt
(
j
)){
arr
[
i
][
j
]
=
arr
[
i
+
1
][
j
-
1
];
if
(
arr
[
i
][
j
]
&&
maxLen
<
len
){
longText
=
str
.
substring
(
i
,
j
+
1
);
maxLen
=
len
;
}
}
else
{
arr
[
i
][
j
]
=
false
;
}
}
}
return
longText
;
}
public
static
void
main
(
String
[]
args
)
{
//String value = searchMaxStr("abcaabb23435dd987ff");
//System.out.println(value);
String
result
=
getLongText1
(
"ac1d2ff2d1db"
);
System
.
out
.
println
(
result
);
}
}
testlib/src/main/java/I2019/A003/TreeNode.java
0 → 100644
浏览文件 @
d3fec083
package
I2019.A003
;
/**
* Description: <TreeNode><br>
* Author: mxdl<br>
* Date: 2019/9/1<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public
class
TreeNode
{
public
int
val
;
public
TreeNode
leftNode
;
public
TreeNode
rightNode
;
public
TreeNode
(
int
val
)
{
this
.
val
=
val
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录