剑指Offer-4
来源:互联网 发布:自动统计数字表格软件 编辑:程序博客网 时间:2024/06/06 03:06
题目:
请实现一个函数,把字符串中的每个空格替换成”%20”,例如”We are happy.”,则输出”We%20are%20happy.”
实现
// coding = javaimport java.util.ArrayList;import java.util.List;public class Solution4 { public static void replaceString(String input){ if(input.length()<1){ return; } List str_list = new ArrayList<Character>(); for(int i =0;i<input.length();i++){ char ch = input.charAt(i); if(ch ==' '){ str_list.add('%'); str_list.add('2'); str_list.add('0'); } else{ str_list.add(ch); } } String result =""; for(int i =0;i<str_list.size();i++) { result += str_list.get(i); } System.out.print(result); } public static void main(String[] args){ String input = "We are happy."; Solution4.replaceString(input); }}
阅读全文
1 0
- 剑指offer chapter 4
- 剑指Offer刷题(4)
- 剑指offer-java(4)
- 剑指Offer-4
- 【剑指offer】题目4
- 剑指Offer读书笔记4
- 剑指offer(4)
- 剑指offer:4-替换空格
- 剑指offer面试题4
- 剑指offer-4 替换空格
- 剑指offer 4- 替换空格
- 剑指offer 面试题4
- 剑指Offer-4-替换空格
- 《剑指offer》4:替换空格
- 剑指offer读书笔记(4)
- 【面试题】剑指offer 4
- 剑指Offer 4 替换空格
- 剑指offer面试题4
- 不想34被裁退_好好学学大数据吧
- ES6总结--Symbol、Set 和 Map 、Iterator、Class
- POI导入工具类+ layer弹窗 实例
- 变量定义法 True/False 全屏窗口
- ES6总结--Proxy、Reflect
- 剑指Offer-4
- res中layout 和drawable目录的介绍
- c语言 文件操作
- 删除oracle12c 数据库
- 微信公众号开发
- 日期计算函数:已知当前日期,求过了一段时间后的日期。
- Myeclipse不自动编译问题
- 数据操作
- ES6总结--Promise 、Generator 、Async/Await