3ms Accepted Java Solution


  • 0
    M
    public class Solution {
        public String reverseString(String s) {
            if (s.isEmpty() || s.length() == 1 || s.equals(null)) {return s;} 
           else {
    		 char[] ch = s.toCharArray();
    		 int firstHalf = 0;
    		 for (int i = ch.length - 1; i >= ch.length / 2; i--) {
    			char temp= ch[firstHalf];
    			ch[firstHalf++] = ch[i];
    			ch[i] = temp;
    		}
    		return new String(ch);
    	}
        }
    }
    

  • 0
    F

    s.eqauls(null) this will never return true


Log in to reply
 

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