public void sortColorBetter(int[] nums) {
		if (nums == null || nums.length <= 1) {
			return;
		}
		
		int nr = 0, nb = nums.length - 1;
		
		// find the fist element that is not red
		while (nr < nums.length && nums[nr]==0) {
			nr++;
		}
		
		// find the first element from left that is not blue
		while (nb >=0 && nums[nb]==2) {
			nb--;
		}
		
		int i = nr;
		
		while (i <= nb) {
			if (nums[i] == 0) {
				swap(nums, i, nr);
				nr++;
				i++;
			} else if (nums[i] == 2) {
				swap(nums, i, nb);
				nb--;
			} else {
				i++;
			}
		}
	}