Created
October 6, 2024 17:32
-
-
Save mohneesh7/cbfc7c367b75b528b8666378cd2c67fe to your computer and use it in GitHub Desktop.
Solution for Merge Strings Alternately
This file contains hidden or 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
# 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