This solution received "Time Limit Exceeded", but isn't this O(n)?


  • 0
    J

    The code runs without error, and the input "hello" returns "olleh".

    public class Solution {
        public String reverseString(String s) {
            char[] arrayString = s.toCharArray();
            String stringReverse = "";
            for (int i = 0; i < s.length(); i++) {
                stringReverse = arrayString[i] + stringReverse;
            }
            return stringReverse;
        }
    }
    

Log in to reply
 

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