Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
home_work
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
牛家玺
home_work
Commits
ffd65ffa
Commit
ffd65ffa
authored
Jan 22, 2019
by
牛家玺
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ok
parent
002805fe
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
136 additions
and
12 deletions
+136
-12
hw1/Heater2.py
+6
-0
hw1/IntReverse.py
+66
-0
hw1/LengthOfLongestSubstring.py
+33
-0
hw1/PeakIndexInMountainArray.py
+1
-2
hw1/ToeplitzMatrix.py
+3
-0
hw1/Zconvert.py
+11
-7
hw1/test.py
+16
-3
No files found.
hw1/Heater2.py
View file @
ffd65ffa
...
...
@@ -4,6 +4,7 @@ class Heater:
houses
.
sort
()
radius
=
0
i
=
0
# 哨兵
heaters
=
[
-
1
]
+
heaters
+
[
float
(
'inf'
)]
for
house
in
houses
:
while
house
>
heaters
[
i
]:
...
...
@@ -13,6 +14,11 @@ class Heater:
print
(
radius
)
houses
=
[
1
,
2
,
4
,
9
]
heaters
=
[
-
1
,
1
,
8
,
float
(
'inf'
)]
Heater
()
.
findRadius
(
houses
,
heaters
)
houses
=
[
1
,
2
,
3
]
heaters
=
[
2
]
Heater
()
.
findRadius
(
houses
,
heaters
)
...
...
hw1/IntReverse.py
0 → 100644
View file @
ffd65ffa
class
Solution
:
def
reverse
(
self
,
x
):
"""
:type x: int
:rtype: int
"""
stark
=
[]
symbol
=
""
for
c
in
str
(
x
):
if
c
!=
'-'
:
stark
.
append
(
c
)
else
:
symbol
=
'-'
value
=
""
if
symbol
!=
""
:
value
=
value
+
symbol
while
stark
:
value
=
value
+
stark
.
pop
()
rtype
=
int
(
value
)
if
rtype
>
2147483647
or
rtype
<
-
2147483648
:
return
0
else
:
return
rtype
i
=
123
Solution
()
.
reverse
(
i
)
i
=
-
123
Solution
()
.
reverse
(
i
)
i
=
120
Solution
()
.
reverse
(
i
)
class
Solution1
:
def
reverse
(
self
,
x
):
"""
:type x: int
:rtype: int
"""
max
=
2147483647
sign
=
1
if
x
>=
0
else
-
1
y
=
0
while
True
:
a
=
x
//
10
b
=
x
-
a
*
10
y
=
b
+
y
*
10
x
=
a
if
y
>
max
:
return
0
if
x
==
0
:
return
sign
*
y
i
=
123
print
(
Solution1
()
.
reverse
(
i
))
i
=
-
123
print
(
Solution1
()
.
reverse
(
i
))
i
=
120
print
(
Solution1
()
.
reverse
(
i
))
hw1/LengthOfLongestSubstring.py
0 → 100644
View file @
ffd65ffa
"""
给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。
示例 1:
输入: "abcabcbb"
输出: 3
解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。
示例 2:
输入: "bbbbb"
输出: 1
解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。
示例 3:
输入: "pwwkew"
输出: 3
解释: 因为无重复字符的最长子串是 "wke",所以其长度为 3。
请注意,你的答案必须是 子串 的长度,"pwke" 是一个子序列,不是子串
"""
class
Solution
:
def
lengthOfLongestSubstring
(
self
,
s
):
"""
:type s: str
:rtype: int
"""
index
=
0
next
=
index
+
1
for
c
in
s
:
print
(
c
)
hw1/PeakIndexInMountainArray.py
View file @
ffd65ffa
...
...
@@ -4,8 +4,7 @@ def peakIndexInMountainArray(mountain):
while
low
<=
height
:
mid
=
(
height
+
low
)
//
2
if
array
[
mid
]
>
array
[
mid
-
1
]
and
array
[
mid
]
>
array
[
mid
+
1
]:
print
(
mid
)
break
return
mid
elif
array
[
mid
]
>
array
[
mid
+
1
]:
height
=
mid
-
1
else
:
...
...
hw1/ToeplitzMatrix.py
View file @
ffd65ffa
...
...
@@ -12,9 +12,12 @@ def isToeplitzMatri(matrix):
[1,2,3,4],
[5,1,2,3],
[9,5,1,2]
"""
matrix
=
[[
1
,
2
,
3
,
4
],
[
5
,
1
,
2
,
3
],
[
9
,
5
,
1
,
2
]]
print
(
isToeplitzMatri
(
matrix
))
hw1/Zconvert.py
View file @
ffd65ffa
def
convert
(
s
,
numRows
):
# 初始化数组
if
numRows
!=
1
:
return
s
rows
=
[
''
]
*
numRows
index
=
0
isInc
=
True
...
...
@@ -16,12 +18,14 @@ def convert(s, numRows):
for
row
in
rows
:
str
=
str
+
row
print
(
str
)
return
str
str
=
"0123456789"
str
=
"LEETCODEISHIRING"
convert
(
str
,
3
)
convert
(
str
,
4
)
#
# str = "0123456789"
# str = "LEETCODEISHIRING"
#
# convert(str, 3)
# convert(str, 4)
str
=
"AB"
print
(
convert
(
str
,
1
))
hw1/test.py
View file @
ffd65ffa
...
...
@@ -2,23 +2,36 @@ def quick_sort(array, l, r):
if
l
>=
r
:
return
stack
=
[]
# 存储分区 左 右 0,6 的索引
stack
.
append
(
l
)
stack
.
append
(
r
)
while
stack
:
while
stack
:
# 如果没数据表示所有分区结束
low
=
stack
.
pop
(
0
)
high
=
stack
.
pop
(
0
)
# 越界检查
if
high
-
low
<=
0
:
continue
# 取右值x作为基准
x
=
array
[
high
]
i
=
low
-
1
# 从左边开始遍历
for
j
in
range
(
low
,
high
):
# 是否小于等于基准值x
# 每次交换都放到左边 如果小于基准值
# 1, 7, 8, 9, 30, 5, 6
# x = 6
# i = -1
# j=0 i=0 1 < 6 j 和 i 交换
# j=5 i=1 5 > 6 j 和 i 交换
if
array
[
j
]
<=
x
:
i
+=
1
i
=
i
+
1
array
[
i
],
array
[
j
]
=
array
[
j
],
array
[
i
]
# 最后取第一个比x值的和x值交换 这样 第一遍排序 1 5 6 9 30 7 8 x=6
array
[
i
+
1
],
array
[
high
]
=
array
[
high
],
array
[
i
+
1
]
# 根据x值分区 low~i 是比当前x小的 x+1 是当前的x值 i+2~high 是比当前x值大的
stack
.
extend
([
low
,
i
,
i
+
2
,
high
])
print
(
array
)
array
=
[
1
,
7
,
8
,
9
,
30
,
5
,
6
]
quick_sort
(
array
,
0
,
len
(
array
)
-
1
)
quick_sort
(
array
,
0
,
len
(
array
)
-
1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment