Shorter concat [Reverse longer]description:
Given 2 strings, a
and b
, return a string of the form:shorter+reverse(longer)+shorter.
In other words, the shortest string have to is put as prefix and as suffix of the reverse of the longest.
Strings a
b
and May is empty, but is not null (in C # Strings may also is null. Treat them as if they is empty.).
If and has the a
b
same length treat as the a
longer producingb+reverse(a)+b
My solution to the dissatisfaction is that if and else judge too much.
An empty string and a non-empty string, which can be directly spliced
usingSystem;usingSystem.Linq;classreverselonger{ Public Static stringShorterreverselonger (stringAstringb) {a= a??string. Empty; b= b??string. Empty; stringstr =string. Empty; if(A.equals (string. Empty)) {if(B.equals (string. Empty)) {}Else{str=string. Join (string. Empty, B.reverse ()); } } Else { if(B.equals (string. Empty)) {str=string. Join (string. Empty, A.reverse ()); } Else { if(A.length <b.length) {STR= A +string. Join (string. Empty, B.reverse ()) +A; } Else{str= B +string. Join (string. Empty, A.reverse ()) +b; } } } returnstr; }}
Other people's Solution:
Better than I was, by comparing size, then using a uniform format to handle
usingSystem.Linq;classreverselonger{ Public Static stringShorterreverselonger (stringAstringb) {if(A = =NULL) A=string. Empty; if(b = =NULL) b=string. Empty; if(A.length <b.length) { stringD =A; A=b; b=D; } returnB + (New string(A.reverse (). ToArray ())) +b; }}
Shorter concat [Reverse longer]