Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Damon-Da
leetcode
提交
5e19abe8
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,发现更多精彩内容 >>
提交
5e19abe8
编写于
1月 24, 2019
作者:
L
liu13
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
20190122
上级
49eb5a0f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
124 addition
and
1 deletion
+124
-1
TopInterview.md
TopInterview.md
+3
-1
code/lc36.java
code/lc36.java
+28
-0
code/lc50.java
code/lc50.java
+20
-0
code/lc54.java
code/lc54.java
+70
-0
readme.md
readme.md
+3
-0
未找到文件。
TopInterview.md
浏览文件 @
5e19abe8
...
...
@@ -26,6 +26,7 @@
| 033 |
[
Search in Rotated Sorted Array
](
https://leetcode.com/problems/search-in-rotated-sorted-array/
)
|Medium|
[
Java
](
./code/lc33.java
)
| 034 |
[
Search for a Range
](
https://leetcode.com/problems/search-for-a-range/
)
|Medium|
[
Java
](
./code/lc34.java
)
| 035 |
[
Search Insert Position
](
https://leetcode.com/problems/search-insert-position/
)
|Medium|
[
Java
](
./code/lc35.java
)
| 036 |
| 041 |
...
...
@@ -35,9 +36,10 @@
| 046 |
[
Permutations
](
https://leetcode.com/problems/permutations/
)
|Medium|
[
Java
](
./code/lc46.java
)
| 048 |
[
Rotate Image
](
https://leetcode.com/problems/rotate-image/
)
|Medium|
[
Java
](
./code/lc48.java
)
| 049 |
[
Group Anagrams
](
https://leetcode.com/problems/anagrams/
)
|Medium|
[
Java
](
./code/lc49.java
)
| 050 |
| 053 |
[
Maximum Subarray
](
https://leetcode.com/problems/maximum-subarray/
)
|Medium|
[
Java
](
./code/lc53.java
)
| 054 |
| 055 |
[
Jump Game
](
https://leetcode.com/problems/jump-game/
)
|Medium|
[
Java
](
./code/lc55.java
)
| 056 |
[
Merge Intervals
](
https://leetcode.com/problems/merge-intervals/
)
|Medium|
[
Java
](
./code/lc56.java
)
| 062 |
[
Unique Paths
](
https://leetcode.com/problems/unique-paths/
)
|Medium|
[
Java
](
./code/lc62.java
)
...
...
code/lc36.java
0 → 100644
浏览文件 @
5e19abe8
package
code
;
/*
* 36. Valid Sudoku
* 题意:横排,竖排,3*3不能包含相同数字
* 难度:Medium
* 分类:Hash Table
* 思路:用一个Set即可,把行号,列号拼上去
* Tips:注意add如果已经有了,返回的是false
*/
import
java.util.HashSet
;
public
class
lc36
{
public
boolean
isValidSudoku
(
char
[][]
board
)
{
HashSet
<
String
>
hs
=
new
HashSet
();
// 如果此set已包含该元素,则该调用不更改set并返回false。
for
(
int
i
=
0
;
i
<
board
.
length
;
i
++)
{
for
(
int
j
=
0
;
j
<
board
[
0
].
length
;
j
++)
{
if
(
board
[
i
][
j
]==
'.'
)
continue
;
boolean
flag1
=
hs
.
add
(
board
[
i
][
j
]+
"row"
+
i
);
boolean
flag2
=
hs
.
add
(
board
[
i
][
j
]+
"col"
+
j
);
boolean
flag3
=
hs
.
add
(
board
[
i
][
j
]+
"box"
+
i
/
3
+
j
/
3
);
if
((!
flag1
)||(!
flag2
)||(!
flag3
))
{
return
false
;
}
}
}
return
true
;
}
}
code/lc50.java
0 → 100644
浏览文件 @
5e19abe8
package
code
;
/*
* 50. Pow(x, n)
* 题意:幂运算
* 难度:Medium
* 分类:Math, Binary Search
* 思路:和lc29的思路类似,数值上的二分。用前一步的结果进行下一步的运算,降低了迭代次数
* Tips:注意溢出的情况,负数的情况。
*/
public
class
lc50
{
public
double
myPow
(
double
x
,
int
n
)
{
if
(
n
==
0
)
return
1
;
if
(
n
==
Integer
.
MIN_VALUE
&&
x
!=
1
&&
x
!=-
1
)
return
0
;
if
(
n
<
0
){
n
=
-
n
;
x
=
1
/
x
;
//负数变成 1/x
}
return
(
n
%
2
==
0
)
?
myPow
(
x
*
x
,
n
/
2
)
:
x
*
myPow
(
x
*
x
,
n
/
2
);
}
}
code/lc54.java
0 → 100644
浏览文件 @
5e19abe8
package
code
;
/*
* 54. Spiral Matrix
* 题意:螺旋输出矩阵
* 难度:Medium
* 分类:Array
* 思路:很直接的思路,就是循环打印
* Tips:需要注意很多细节,最后调试成功
*/
import
java.util.ArrayList
;
import
java.util.List
;
public
class
lc54
{
public
static
void
main
(
String
[]
args
)
{
int
[][]
matrix
=
{{
1
,
2
,
3
,
4
},{
5
,
6
,
7
,
8
},{
9
,
10
,
11
,
12
}};
System
.
out
.
println
(
spiralOrder
(
matrix
));
}
public
static
List
<
Integer
>
spiralOrder
(
int
[][]
matrix
)
{
List
<
Integer
>
res
=
new
ArrayList
<>();
if
(
matrix
.
length
==
0
)
return
res
;
int
r
=
0
,
c
=-
1
;
// -1开始,循环内首先++
int
row_r
=
matrix
.
length
;
int
col_r
=
matrix
[
0
].
length
;
int
row_l
=
-
1
;
int
col_l
=-
1
;
while
(
row_l
+
1
<
row_r
||
col_l
+
1
<
col_r
){
c
++;
if
(
c
<
col_r
){
while
(
c
<
col_r
){
res
.
add
(
matrix
[
r
][
c
]);
c
++;
}
}
else
//提前终止
return
res
;
c
--;
// -- 恢复正常
r
++;
if
(
r
<
row_r
)
{
while
(
r
<
row_r
)
{
res
.
add
(
matrix
[
r
][
c
]);
r
++;
}
}
else
return
res
;
r
--;
c
--;
if
(
c
>
col_l
){
while
(
c
>
col_l
){
res
.
add
(
matrix
[
r
][
c
]);
c
--;
}
}
else
return
res
;
c
++;
r
--;
if
(
r
>
row_l
+
1
)
{
while
(
r
>
row_l
+
1
)
{
res
.
add
(
matrix
[
r
][
c
]);
r
--;
}
}
else
return
res
;
r
++;
row_l
++;
row_r
--;
col_l
++;
col_r
--;
}
return
res
;
}
}
readme.md
浏览文件 @
5e19abe8
...
...
@@ -39,6 +39,7 @@ Language: Java
| 032
[
Java
](
./code/lc32.java
)
| 033
[
Java
](
./code/lc33.java
)
| 034
[
Java
](
./code/lc34.java
)
| 036
[
Java
](
./code/lc36.java
)
| 038
[
Java
](
./code/lc38.java
)
| 039
[
Java
](
./code/lc39.java
)
| 041
[
Java
](
./code/lc41.java
)
...
...
@@ -47,7 +48,9 @@ Language: Java
| 046
[
Java
](
./code/lc46.java
)
| 048
[
Java
](
./code/lc48.java
)
| 049
[
Java
](
./code/lc49.java
)
| 050
[
Java
](
./code/lc50.java
)
| 053
[
Java
](
./code/lc53.java
)
| 054
[
Java
](
./code/lc54.java
)
| 055
[
Java
](
./code/lc55.java
)
| 056
[
Java
](
./code/lc56.java
)
| 058
[
Java
](
./code/lc58.java
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录