We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Algorithms
- Strings
- Morgan and a String
- Discussions
Morgan and a String
Morgan and a String
Sort by
recency
|
312 Discussions
|
Please Login in order to post a comment
import java.util.; import java.text.; import java.math.; import java.util.regex.;
public class Solution { static String morganAndString(String a, String b) { // Complete this function int lenA = a.length(), lenB = b.length(); StringBuilder sb = new StringBuilder(); int pA = 0, pB = 0; while (pA < lenA && pB < lenB) { if (a.charAt(pA) < b.charAt(pB)) { sb.append(a.charAt(pA++)); }else if (a.charAt(pA) > b.charAt(pB)) { sb.append(b.charAt(pB++)); }else { if (compare(a, pA + 1, b, pB + 1)) { sb.append(a.charAt(pA++)); while (pA < a.length() && a.charAt(pA) == a.charAt(pA - 1)) { sb.append(a.charAt(pA++)); } } else { sb.append(b.charAt(pB++)); while (pB < b.length() && b.charAt(pB) == b.charAt(pB - 1)) { sb.append(b.charAt(pB++)); } } } }
}
solution in scala
def morganAndString(inputA: String, inputB: String): String = { var posA = 0 var posB = 0 val sb = new StringBuilder(inputA.length + inputB.length)
Do you have any idea why i'm getting just half of the test cases? def morganAndString(a, b):
Could any one give a simple case that might fail this logic? def morganAndString(a, b): j=0 k=0 c=[] while jb[k:]: c+=b[k] k+=1 if j
Use this C++ Code