剑指 Offer 05. 替换空格 Author: Brandon Ng Date: June 15, 2022 11:09:28 剑指 Offer 05. 替换空格 题目描述请实现一个函数,把字符串 s 中的每个空格替换成”%20”。 输入输出12输入:s = "We are happy."输出:"We%20are%20happy." 基本思路没啥好说的 循环然后用一个StringBuilder接受就行了 java实现12345678910class Solution { public String replaceSpace(String s) { StringBuilder sb = new StringBuilder(); for(Character c:s.toCharArray()){ if(c == ' ') sb.append("%20"); else sb.append(c); } return sb.toString(); }} Tag(s): # algorithm-Easy # algorithm-字符串 back · home 剑指 Offer 10- I. 斐波那契数列 剑指 Offer 56 - I. 数组中数字出现的次数