标签:problems span rip oct return origin tno nbsp 反转
leetcode地址:https://leetcode.com/problems/reverse-words-in-a-string-iii/description/
题目:一个字符串,单词反转
Input: "Let‘s take LeetCode contest" Output: "s‘teL ekat edoCteeL tsetnoc"
class Solution { public String reverseWords(String s) { String[] strArray = s.split(" "); String result = ""; for(int i=0;i<strArray.length;i++) { result += reverse(strArray[i]); if(i != strArray.length) result += " "; } return result; } public String reverse(String originStr) { if(originStr == null || originStr.length() <= 1) return originStr; return reverse(originStr.substring(1)) + originStr.charAt(0); } }
4.Reverse Words in a String III
标签:problems span rip oct return origin tno nbsp 反转
原文地址:http://www.cnblogs.com/zhangtao1993/p/7478592.html