## Problem:

Given two strings, append them together (known as "concatenation") and return the result. However, if the strings are different lengths, omit chars from the longer string so it is the same length as the shorter string. So "Hello" and "Hi" yield "loHi". The strings may be any length.

minCat("Hello", "Hi") → "loHi"
minCat("Hello", "java") → "ellojava"
minCat("java", "Hello") → "javaello"

## Solution:

public String minCat(String a, String b) {
if (a.length() == b.length())
return a+b;
if (a.length() > b.length()){
int diff = a.length() - b.length();
return a.substring(diff, a.length()) + b;

} else {
int diff = b.length() - a.length();
return a + b.substring(diff, b.length());
}

}

1. public String minCat(String a, String b) {
int lengthA = a.length();
int lengthB = b.length();
if (lengthA>lengthB) {
//return a.substring(b.length())+b;
a = a.substring(lengthA-lengthB);
}
else if (lengthB>lengthA) {
b = b.substring(lengthB-lengthA);
}
return a.concat(b);
}

2. public String minCat(String a, String b) {
if(a.length() > b.length())
return a.substring(a.length()-b.length()) + b;
else if(a.length() < b.length())
return a + b.substring(b.length()-a.length());
return a.substring(a.length()-2) + b;
}

3. public String minCat(String a, String b) {
int aLen = a.length();
int bLen = b.length();

if(aLen>bLen && aLen != 0 && bLen != 0)
return a.substring(aLen-bLen,aLen)+b;
else if(bLen>aLen && aLen != 0 && bLen != 0)
return a+b.substring(bLen-aLen,bLen);
else return "";
}

4. public String minCat(String a, String b) {
String result="";
if(a.length()<b.length()){
result+= a+b.substring(b.length()-a.length(),b.length());
}
if(b.length()<a.length()){
result+= a.substring(a.length()-b.length(),a.length())+b;
}
if(a.length()==b.length()){
result+= a+b;
}
return result;
}

5. public String minCat(String a, String b) {
if(a.length() > b.length())
{
return a.substring(a.length()-b.length(),a.length())+b;
}
else
{
return a+b.substring(b.length()-a.length(),b.length());
}

}

6. public String minCat(String a, String b) {
if(a.length() <= b.length())
{
return a + b.substring(b.length() - a.length());
}
return a.substring(a.length() - b.length()) + b;

}

7. public String minCat(String a, String b) {
int min=Math.min(a.length(),b.length());
return a.substring(a.length()-min) + b.substring(b.length()-min);
}

1. I just saw we had the same approach! Lol, this solution is so much shorter and easier to follow.

8. public String minCat(String a, String b) {
int size = Math.min(a.length(), b.length());
return a.substring(a.length()- size) + b.substring(b.length()-size);

}

9. public String minCat(String a, String b) {
if(a.length()<b.length()) {
return a + b.substring(b.length() - a.length());
}
return a.substring(a.length()-b.length())+b;

}

10. public String minCat(String a, String b) {
String str = a.length() >= b.length() ? a.substring(a.length()-b.length()) + b : a + b.substring(b.length()-a.length());
return str;
}

11. public String minCat(String a, String b) {
if (a.length() == b.length()) {
return a + b;
}
int differenceA = a.length() - b.length();
int differenceB = b.length() - a.length();
return (a.length() > b.length()) ? (a.substring(differenceA) + b) : (a + b.substring(differenceB));
}

12. public String minCat(String a, String b) {
int x=a.length()-b.length();
int y=b.length()-a.length();
if(x>y){
return a.substring(x,a.length())+b;
}if(x<y){
return a+b.substring(y,b.length());
}return "";

}

13. public String minCat(String a, String b)
{
String str="";
int alen=a.length();
int blen = b.length();

if(alen>blen)
{
str=a.substring((a.length()-b.length()), a.length()) + b.substring(0,b.length());
}
else
{
str= a.substring(0,a.length()) + b.substring((b.length()-a.length()), b.length() );
}

return str;
}

14. public String minCat(String a, String b)
{
if (a.length() > b.length())
return a.substring(a.length()-b.length()) + b;

if (b.length() > a.length())
return a+b.substring(b.length()-a.length());

return a+b;
}

15. public String minCat(String a, String b) {
int min=Math.min(a.length(),b.length());
return a.substring(a.length()-min) + b.substring(b.length()-min);
}

16. public String minCat(String a, String b) {
if (b.length()<a.length())
return a.substring(a.length()-b.length(),a.length()) +b;
return a +b.substring(b.length()-a.length(),b.length());
}

//simple coing

17. public String minCat(String a, String b) {
int max = Math.max(a.length(),b.length());
return a.substring(max-b.length()) + b.substring(max-a.length());

}

18. public String minCat(String a, String b)
{
String smaller = a;

if(b.length() < smaller.length())
smaller = b;

String data = "";

if(smaller.equals(a))
data += a + b.substring(b.length() - smaller.length() );
else if(smaller.equals(b))
data += a.substring(a.length() - smaller.length()) + b;

return data;
}

19. public String minCat(String a, String b) {
StringBuilder newStr = new StringBuilder();

if(a.length() > b.length()){
newStr.append(a.substring(a.length()-b.length(),a.length()) + b);
}

if(b.length() > a.length()){
newStr.append(a + b.substring(b.length()-a.length(),b.length()));
}

return newStr.toString();
}

20. public String minCat(String a, String b) {
if(a.length() > b.length()){
return a.substring(a.length()-b.length(), a.length()).concat(b);
} else if(b.length() > a.length()){
return a.concat(b.substring(b.length()-a.length(), b.length()));
}
return a.concat(b);
}