GitBook: [#2] No subject
This commit is contained in:
@ -2,13 +2,14 @@
|
||||
|
||||
## 题目链接
|
||||
|
||||
[牛客网](https://www.nowcoder.com/practice/ef1f53ef31ca408cada5093c8780f44b?tpId=13&tqId=11166&tab=answerKey&from=cyc_github)
|
||||
[牛客网](https://www.nowcoder.com/practice/ef1f53ef31ca408cada5093c8780f44b?tpId=13\&tqId=11166\&tab=answerKey\&from=cyc\_github)
|
||||
|
||||
## 题目描述
|
||||
|
||||
需要保证奇数和奇数,偶数和偶数之间的相对位置不变,这和书本不太一样。例如对于 [1,2,3,4,5],调整后得到 [1,3,5,2,4],而不能是 {5,1,3,4,2} 这种相对位置改变的结果。
|
||||
需要保证奇数和奇数,偶数和偶数之间的相对位置不变,这和书本不太一样。例如对于 \[1,2,3,4,5],调整后得到 \[1,3,5,2,4],而不能是 {5,1,3,4,2} 这种相对位置改变的结果。
|
||||
|
||||
\
|
||||
|
||||
<div align="center"> <img src="https://cs-notes-1256109796.cos.ap-guangzhou.myqcloud.com/d03a2efa-ef19-4c96-97e8-ff61df8061d3.png" width="200px"> </div><br>
|
||||
|
||||
## 解题思路
|
||||
|
||||
@ -37,7 +38,7 @@ private boolean isEven(int x) {
|
||||
}
|
||||
```
|
||||
|
||||
方法二:使用冒泡思想,每次都将当前偶数上浮到当前最右边。时间复杂度 O(N<sup>2</sup>),空间复杂度 O(1),时间换空间。
|
||||
方法二:使用冒泡思想,每次都将当前偶数上浮到当前最右边。时间复杂度 O(N2),空间复杂度 O(1),时间换空间。
|
||||
|
||||
```java
|
||||
public int[] reOrderArray(int[] nums) {
|
||||
|
Reference in New Issue
Block a user