剑指 Offer 05. 替换空格
请实现一个函数,把字符串 s 中的每个空格替换成"+"。
示例 1:
输入:s = "We are happy."
输出:"We+are+happy."
限制:
0 <= s 的长度 <= 10000
题目链接:
https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/
Java 实现:
package org.ben.powerbutton.SeventhNovember;
/**
* @Author: Ben
* @Date: 2020/11/7 16:17
*/
public class Test2 {
/**
* 替换空格
*
* 请实现一个函数,把字符串 s 中的每个空格替换成"+"。
* 示例 1:
* 输入:s = "We are happy."
* 输出:"We+are+happy."
* 题目链接:
* https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof/
* @param args
*/
public static void main(String[] args) {
String s="ab ede ";
System.out.println(new Test2().replaceSpace(s));
}
public String replaceSpace(String s) {
return s.replaceAll(" ","+");
}
}
C#实现:
namespace powerbutton { public class Test2 { public string ReplaceSpace(string s) { return s.Replace(" ", "+"); } } } using System; namespace powerbutton { class Program { static void Main(string[] args) { Console.WriteLine(new Test2().ReplaceSpace("ab ede ")); } } }
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于