Skip to content

Msdftd/SortColor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

SortColor

leedcode problem number 75

package leetcode.medium;

class SortColors {

void sortColors(int[] nums) {

int start = 0;
int mid = 0;
int end = nums.length - 1;

while (mid <= end) {

  switch (nums[mid]) {
    case 0:
      // Swap with start index
      swap(nums, start, mid);
      mid++;
      start++;
      break;

    case 1:
      mid++;
      break;

    case 2:
      // Swap with end index
      swap(nums, mid, end);
      end--;
      break;
  }
}

}

private void swap(int[] arr, int pos1, int pos2) { int temp = arr[pos1]; arr[pos1] = arr[pos2]; arr[pos2] = temp; }

}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published