From c5ea70b1ca9e1f4152fd8fa487d9d93c8b0ebd75 Mon Sep 17 00:00:00 2001 From: kfc966 <76138585+kfc966@users.noreply.github.com> Date: Tue, 1 Mar 2022 11:16:24 +0800 Subject: [PATCH] =?UTF-8?q?Update=20Leetcode=20=E9=A2=98=E8=A7=A3=20-=20?= =?UTF-8?q?=E6=8E=92=E5=BA=8F.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit heihei --- notes/Leetcode 题解 - 排序.md | 41 ++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/notes/Leetcode 题解 - 排序.md b/notes/Leetcode 题解 - 排序.md index 36a31e3d..1faa1617 100644 --- a/notes/Leetcode 题解 - 排序.md +++ b/notes/Leetcode 题解 - 排序.md @@ -224,21 +224,32 @@ Output: [0,0,1,1,2,2] ```java public void sortColors(int[] nums) { - int zero = -1, one = 0, two = nums.length; - while (one < two) { - if (nums[one] == 0) { - swap(nums, ++zero, one++); - } else if (nums[one] == 2) { - swap(nums, --two, one); - } else { - ++one; + int p0=0; + int p1=0; + for(int i=0;i