Reverse String

来源:互联网 发布:mysql 降序 desc 编辑:程序博客网 时间:2024/06/17 19:07

Write a function that takes a string as input and returns the string reversed.

Example:
Given s = "hello", return "olleh".

Subscribe to see which companies asked this question.

点击打开链接

简单题 不赘述 两行代码

public String reverseString(String s) {        StringBuffer s1=new StringBuffer(s);        return s1.reverse().toString();    }
自己写也可以

StringBuffer s1=new StringBuffer();        for(int i=s.length()-1;i>=0;i--){           s1=s1.append(s.charAt(i)) ;        }        return s1.toString();



原创粉丝点击