Make duplicate to zero
// last
// |
// 1 1 1 2 2 5 6, (1) last=arr[i]: a[i]=0 (2) else: last=a[i]: 1 0 0 2 0 5 6
func zeroDuplicate(nums []int) {
last := nums[0]
for i := 1; i < len(nums); i++ {
if nums[i] == last {
nums[i] = 0
} else {
last = nums[i]
}
}
}
Bubble Sorting
func bubbleSort(nums []int) {
for i := 0; i < len(nums); i++ {
for j := 0; j < len(nums)-1-i; j++ {
if nums[j] > nums[j+1] {
nums[j], nums[j+1] = nums[j+1], nums[j]
}
}
}
}