Skip to content

Instantly share code, notes, and snippets.

@orcaman
Created January 1, 2017 20:40
Show Gist options
  • Save orcaman/d499f54ef4830a2dfaf2bb0fe1a2b8ed to your computer and use it in GitHub Desktop.
Save orcaman/d499f54ef4830a2dfaf2bb0fe1a2b8ed to your computer and use it in GitHub Desktop.
func merge(l, r []int) []int {
ret := make([]int, 0, len(l)+len(r))
for len(l) > 0 || len(r) > 0 {
if len(l) == 0 {
return append(ret, r...)
}
if len(r) == 0 {
return append(ret, l...)
}
if l[0] <= r[0] {
ret = append(ret, l[0])
l = l[1:]
} else {
ret = append(ret, r[0])
r = r[1:]
}
}
return ret
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment