Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
LeetCodeAnimation
Commits
93886784
Unverified
Commit
93886784
authored
Aug 19, 2020
by
程序员吴师兄
Committed by
GitHub
Aug 19, 2020
Browse files
Merge pull request #114 from ztianming/patch-7
Update LeetCode第283号问题:移动零.md
parents
f43c0860
966ccbe6
Changes
1
Show whitespace changes
Inline
Side-by-side
notes/LeetCode第283号问题:移动零.md
View file @
93886784
...
...
@@ -103,8 +103,9 @@ public:

代码如下:
C++ Code:
```
```
c++
// 原地(in place)解决该问题
// 时间复杂度: O(n)
// 空间复杂度: O(1)
...
...
@@ -130,7 +131,44 @@ public:
```
Java Code:
```
java
class
Solution
{
public
void
moveZeroes
(
int
[]
nums
)
{
// 双指针
int
i
=
0
;
for
(
int
j
=
0
;
j
<
nums
.
length
;
j
++)
{
// 不为0,前移
if
(
nums
[
j
]
!=
0
)
{
int
temp
=
nums
[
i
];
nums
[
i
]
=
nums
[
j
];
nums
[
j
]
=
temp
;
i
++;
}
}
}
}
```
Python Code:
```
python
class
Solution
:
def
moveZeroes
(
self
,
nums
:
List
[
int
])
->
None
:
"""
Do not return anything, modify nums in-place instead.
"""
# 双指针
i
=
0
for
j
in
range
(
len
(
nums
)):
# 不为0,前移
if
nums
[
j
]
!=
0
:
nums
[
i
],
nums
[
j
]
=
nums
[
j
],
nums
[
i
]
i
+=
1
```
...
...
Write
Preview
Supports
Markdown
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