Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1_homework_安晓东
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
安晓东
1_homework_安晓东
Commits
5d4ecf62
Commit
5d4ecf62
authored
Jan 14, 2019
by
安晓东
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
第四次作业算法题
parent
3ee68a34
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
0 deletions
+36
-0
lession_4/__init__.py
+0
-0
lession_4/homework_01.py
+20
-0
lession_4/quick_sort.py
+16
-0
No files found.
lession_4/__init__.py
0 → 100644
View file @
5d4ecf62
lession_4/homework_01.py
0 → 100644
View file @
5d4ecf62
def
convert
(
s
,
numRows
):
if
numRows
==
1
and
numRows
>=
len
(
s
):
return
s
li
=
[[]
for
x
in
range
(
numRows
)]
row
,
step
=
0
,
1
for
i
in
s
:
li
[
row
]
.
append
(
i
)
if
row
==
0
:
step
=
1
elif
row
==
numRows
-
1
:
step
=
-
1
row
+=
step
result
=
''
for
y
in
range
(
len
(
li
)
-
1
):
result
=
result
+
''
.
join
(
li
[
y
])
return
result
s
=
convert
(
"PAYPALISHIRING"
,
4
)
print
(
s
)
lession_4/quick_sort.py
0 → 100644
View file @
5d4ecf62
def
quick_sort
(
sort_list
,
start_index
,
end_index
):
if
start_index
<
end_index
:
# 如果角标左侧小于右侧则开始排序,否则退出
basic
,
i
,
j
=
sort_list
[
start_index
],
start_index
,
end_index
while
i
<
j
:
while
i
<
j
and
basic
<=
sort_list
[
j
]:
# 基准值比j(右侧)小,那么该值不做任何事情
j
-=
1
while
i
<
j
and
basic
>=
sort_list
[
i
]:
i
+=
1
sort_list
[
i
],
sort_list
[
j
]
=
sort_list
[
j
],
sort_list
[
i
]
sort_list
[
i
],
sort_list
[
start_index
]
=
sort_list
[
start_index
],
sort_list
[
i
]
quick_sort
(
sort_list
,
start_index
,
i
-
1
)
quick_sort
(
sort_list
,
i
+
1
,
end_index
)
l
=
[
10
,
6
,
9
,
18
,
20
,
5
,
7
,
15
,
14
,
18
,
19
]
quick_sort
(
l
,
0
,
len
(
l
)
-
1
)
print
(
l
)
\ No newline at end of file
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