Java Time Limit Exceeded issue


  • 0
    E

    public class Solution {
    public String reverseString(String s) {
    String rs="";
    for (int i=s.length(); i>0;i--){
    rs=rs+s.substring(i-1, i);
    }
    return rs;
    }
    }

    I don't know why my answer didn't work. The loop executes n times, thus it should be O(n), right? Anyone help me, thanks!


Log in to reply
 

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