Created
January 1, 2017 20:40
-
-
Save orcaman/d499f54ef4830a2dfaf2bb0fe1a2b8ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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