zoukankan      html  css  js  c++  java
  • 【leetcode】557. Reverse Words in a String III

    原题

    Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

    Example 1:
    Input: "Let's take LeetCode contest"
    Output: "s'teL ekat edoCteeL tsetnoc"
    Note: In the string, each word is separated by single space and there will not be any extra space in the string.

    解析

    传入一个字符串,将每个单词反序,然后依然保留空格输出

    我的解法

    第一次写一行解法,对比了下leetcode上面的最多票数解法要简便许多,可能是因为最多票的解法那时候还没出java8吧

    public class ReverseWordsInAStringIII {
        public static String reverseWords(String s) {
            return Arrays.stream(s.split(" ")).map(w -> new StringBuffer(w).reverse().toString()).collect(Collectors.joining(" ")).toString();
        }
    }
    
  • 相关阅读:
    异常处理
    弹出对话框
    ef——存储过程
    事务
    linq——常用方法
    Linq
    asp get与post获取的区别
    Web服务的调用
    AJAX控件——多层弹出Accordion
    数据绑定
  • 原文地址:https://www.cnblogs.com/shanelau/p/7207439.html
Copyright © 2011-2022 走看看