@Asquare

you were right. what about this?


        public static char[] concat(char[] str1, char[] str2) {


                boolean repeat = false;// indicates whether two neighbor chars
repeat in
                // str1 array

                int pointer = -1; // pointer for str2 array

                for (int i = 0; i < str1.length; i++) {

                        if (pointer + 1 >= str2.length) {
                                pointer = -1;
                                break;
                        }

                        if (str1[i] == str2[pointer + 1]) {

                                pointer++;
                                repeat = (i > 0 && (str1[i] == str1[i - 1]));

                        } else {

                                if (!repeat)
                                        pointer = -1;

                        }

                }

                char[] result = null;

                if (pointer != -1) {
                        result = new char[str1.length + str2.length - (pointer 
+ 1)];

                        System.arraycopy(str1, 0, result, 0, str1.length);
                        System.arraycopy(str2, pointer + 1, result, str1.length,
str2.length
                                        - pointer - 1);
                }

                return result;

        }
On Oct 20, 7:55 am, Asquare <anshika.sp...@gmail.com> wrote:
> @ligerdave -
> your algo will fail in the case the two arrays are:
>
> hellosteeeel
> eeelexander
>
> ans : hellosteeeelexander
> but according to ur method the answer would end up being
> hellosteeeeleeelexander

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to