Advertisement
smj007

Untitled

Apr 19th, 2025
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. class Solution:
  2.     def mergeAlternately(self, word1: str, word2: str) -> str:
  3.      
  4.         i = 0
  5.         j = 0
  6.         answer = ""
  7.  
  8.         while (i<len(word1) and j<len(word2)):
  9.             answer += word1[i] + word2[j]
  10.             i += 1
  11.             j += 1
  12.  
  13.         while (i < len(word1)):
  14.             answer += word1[i]
  15.             i += 1
  16.  
  17.         while (j < len(word2)):
  18.             answer += word2[j]
  19.             j += 1
  20.  
  21.         return answer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement