Skip to content

Commit 371295a

Browse files
committed
奇偶分割数组
1 parent 592a761 commit 371295a

2 files changed

Lines changed: 38 additions & 14 deletions

File tree

README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,20 @@
9393
| LeetCode | 402 | 移掉K位数字 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Stack/RemoveKDigits.cpp) | | ★★★ |
9494

9595
## 双指针
96-
| OJ | # | Title | C++ Solution | Illustration | Importance Leval |
97-
| -------- | --- | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------- | ---------------- |
98-
| LeetCode | 3 | 最长无重复字符子串 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/LongestSubstringWithoutRepeatingCharacters.cpp) | [双指针解题](http://flyrie.top/2018/08/15/Two_Pointers_Algorithm_Solutions/) | |
99-
| LeetCode | 26 | 删除排序数组中的重复项 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/RemoveDuplicatesFromSortedArray.cpp) | | ★★★ |
100-
| LeetCode | 80 | 删除排序数组中的重复项 II | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/RemoveDuplicatesFromSortedArrayII.cpp) | | ★★★ |
101-
| LeetCode | 27 | 移除元素 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/RemoveElement.cpp) | | |
102-
| LeetCode | 42 | 接雨水 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/TrappingRainWater.cpp) | | ★★★ |
103-
| LeetCode | 75 | 颜色分类 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/SortColors.cpp) | | ★★★ |
104-
| LeetCode | 76 | 最小覆盖子串 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/MinimumWindowSubstring.cpp) | | ★★★ |
105-
| LeetCode | 82 | 删除排序链表中的重复元素 II | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/RemoveDuplicatesFromSortedListII.cpp) | | ★★★ |
106-
| LeetCode | 88 | 合并两个有序数组 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/MergeSortedArray.cpp) | | ★★★ |
107-
| LeetCode | 845 | 数组中的最长山脉 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/LongestMountainInArray.cpp) | | ★★★ |
108-
| LeetCode | 283 | 移动零 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/MoveZeroes.cpp) | | ★★★ |
96+
| OJ | # | Title | C++ Solution | Illustration | Importance Leval |
97+
| -------- | --- | ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------- | ---------------- |
98+
| LeetCode | 3 | 最长无重复字符子串 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/LongestSubstringWithoutRepeatingCharacters.cpp) | [双指针解题](http://flyrie.top/2018/08/15/Two_Pointers_Algorithm_Solutions/) | |
99+
| LeetCode | 26 | 删除排序数组中的重复项 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/RemoveDuplicatesFromSortedArray.cpp) | | ★★★ |
100+
| LeetCode | 80 | 删除排序数组中的重复项 II | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/RemoveDuplicatesFromSortedArrayII.cpp) | | ★★★ |
101+
| LeetCode | 27 | 移除元素 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/RemoveElement.cpp) | | |
102+
| LeetCode | 42 | 接雨水 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/TrappingRainWater.cpp) | | ★★★ |
103+
| LeetCode | 75 | 颜色分类 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/SortColors.cpp) | | ★★★ |
104+
| LeetCode | 76 | 最小覆盖子串 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/MinimumWindowSubstring.cpp) | | ★★★ |
105+
| LeetCode | 82 | 删除排序链表中的重复元素 II | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/RemoveDuplicatesFromSortedListII.cpp) | | ★★★ |
106+
| LeetCode | 88 | 合并两个有序数组 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/MergeSortedArray.cpp) | | ★★★ |
107+
| LeetCode | 845 | 数组中的最长山脉 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/LongestMountainInArray.cpp) | | ★★★ |
108+
| LeetCode | 283 | 移动零 | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/MoveZeroes.cpp) | | ★★★ |
109+
| LintCode | 373 | [奇偶分割数组](https://www.lintcode.com/problem/partition-array-by-odd-and-even/description?_from=ladder&&fromId=6) | [C++](https://github.com/feipxyz/Algorithm-Solution/blob/master/Two%20Pointers/PartitionArrayByOddAndEven.cpp) | 剑指offer | ★★★ |
109110

110111
## 字符串
111112
| OJ | # | Title | C++ Solution | Illustration | Importance Leval |
@@ -163,4 +164,5 @@
163164
| 2019-01-11 | [反转链表](https://leetcode.com/problems/reverse-linked-list/) |
164165
| 2019-01-11 | [寻找旋转排序数组中的最小值](https://www.lintcode.com/problem/find-minimum-in-rotated-sorted-array/description?_from=ladder&&fromId=6) |
165166
| 2019-01-11 | [重建二叉树](https://www.lintcode.com/problem/construct-binary-tree-from-preorder-and-inorder-traversal/description) |
166-
| 2019-01-12 | [搜索二维矩阵 II](https://www.lintcode.com/problem/search-a-2d-matrix-ii/description?_from=ladder&&fromId=6) |
167+
| 2019-01-12 | [搜索二维矩阵 II](https://www.lintcode.com/problem/search-a-2d-matrix-ii/description?_from=ladder&&fromId=6) |
168+
| 2019-01-13 | [奇偶分割数组](https://www.lintcode.com/problem/partition-array-by-odd-and-even/description?_from=ladder&&fromId=6) |
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
/*
4+
* @param nums: an array of integers
5+
* @return: nothing
6+
*/
7+
void partitionArray(vector<int> &nums) {
8+
// write your code here
9+
int low = 0;
10+
int high = nums.size() - 1;
11+
while (low < high)
12+
{
13+
while (low < high && nums[low] % 2 == 1)
14+
low++;
15+
while (low < high && nums[high] % 2 == 0)
16+
high--;
17+
swap(nums[low], nums[high]);
18+
low++;
19+
high--;
20+
}
21+
}
22+
};

0 commit comments

Comments
 (0)