Java 3 lines of code, O(n) time and O(1) space


  • 0
    H
    This post is deleted!

  • 1

    How is this O(n)? lastIndexOf() and indexOf() are both O(n), so your solution's worst case will be O(n^2), when the only unique char is at the end.


Log in to reply
 

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