leetcode题目:reverse words in a string

来源:互联网 发布:zookeeper用了什么算法 编辑:程序博客网 时间:2024/06/04 11:28
public class Solution {public static String reverserWords(String s){String[] Array=s.split(" ");int len=Array.length;//length of arrayint low=0;int high=len-1;int i=0;while(i<len && low <=high){String temp=null;temp=Array[i];Array[i]=Array[len-1-i];Array[len-1-i]=temp;low++;high--;i++;}//for//for(int k=0;k<len;k++)//System.out.println(Array[k]);for(int j=1;j<len;j++)Array[0]+=" "+Array[j];return Array[0];}public static void main(String[] args){String test="the sky is blue";String newtest=reverserWords(test);System.out.println(newtest);//the output should be blue is sky the}}


0 0
原创粉丝点击