3 lines 3ms C solution


  • -15
    G
    bool isIsomorphic(char* s, char* t) {
    static char n[512],*m = n + 256;
    return (!*s && !*t && memset(n,0,512)) || (((!(m[*s] || n[*t] || !(m[*s] = *t, n[*t] = *s)) || (m[*s] == *t && n[*t] == *s)) || !memset(n,0,512))  && isIsomorphic(s+1,t+1)); }

  • 0
    S

    Can you explain a bit more about the meanings of these boolean expressions?


  • 9
    S

    By squeezing all the code into one long line, you greatly sacrificed the readability of your code. You may have used some "smart" tricks, but you should at least have the courtesy to try to make people understand it as much as possible, not the opposite.

    By the way, please stop tagging your solution 'constant-space' while using recursion, Your program does strlen(s) recursive calls, and thus it takes O(N) space. Luckily, this is a TAIL recursion, which means you can easily rewrite it as a iterative solution.


Log in to reply
 

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