Skip to content

Instantly share code, notes, and snippets.

@mohneesh7
Created October 6, 2024 17:32
Show Gist options
  • Save mohneesh7/cbfc7c367b75b528b8666378cd2c67fe to your computer and use it in GitHub Desktop.
Save mohneesh7/cbfc7c367b75b528b8666378cd2c67fe to your computer and use it in GitHub Desktop.
Solution for Merge Strings Alternately
# Solution for Merge Strings Alternately
class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
new_string = []
min_length = min(len(word1), len(word2))
if len(word1) != len(word2):
if len(word1) > len(word2):
temp_string = word1[min_length:]
else:
temp_string = word2[min_length:]
else:
temp_string = ''
for x in range(min_length):
new_string.append(word1[x])
new_string.append(word2[x])
new_string = ''.join(new_string) + temp_string
return new_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment