标签:style blog color os io ar for div sp
public class Solution { public String reverseWords(String s) { if(s==null||s.length()==0) return ""; s=reverse(s); String s2[]=s.split("\\s+"); StringBuffer sbf=new StringBuffer(); for(int i=0;i<s2.length;i++) { sbf.append(reverse(s2[i])+" "); } return sbf.toString().trim(); } public String reverse(String s) { char c[]=s.toCharArray(); for(int i=0;i<c.length/2;i++) { char t=c[i]; c[i]=c[s.length()-i-1]; c[s.length()-i-1]=t; } return String.valueOf(c); } }
leetcode 逆转字符串 当年的第一题,今天再写一遍,物是人非
标签:style blog color os io ar for div sp
原文地址:http://www.cnblogs.com/hansongjiang/p/3959869.html