Ad
  • Custom User Avatar

    Cool! I did something similar except I used tail recursion (with a helper function that had an accumulator). This cuts down a little on the space complexity, otherwise need to save the stack trace of each call to persistence so that the result can be summed to 1 in the return statement

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    It's concise and cool but isn't the time complexity O(n^2)? you can do it with O(n) complexity by doing a first pass over the string to record counts of each character in an array (can explit the convertability of ASCII characters to integers) although there is a tradeoff in space complexity and verbosity...

  • Custom User Avatar

    I usually avoid recursive algorithms when easy iterative solutions exist because of the savings in space from the buffered function calls... not to mention the overhead for all the new LinkedLists that are instantiated. Looks cool though.