Why does "a" for haystack and "" for needle would return "a"?

  • 0
        if (needle == "") return haystack;

    I have this one-liner that would specifically handle the case where if needle empty, then return the pointer to the haystack.

    Yet when I compiled this code, the returned result is NULL. Is there something wrong with the test case? Compiled locally, my result is the first pointer to the haystack.

  • 0

    if (needle.equals("")) { return haystack; }

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.