替换空格
来源:互联网 发布:手机多大内存够用 知乎 编辑:程序博客网 时间:2024/06/05 18:41
题目描述
请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。
思路
从后往前替换
class Solution {public: void replaceSpace(char *str,int length) { int i = length-1; while(i >= 0) { if((int)str[i] == 32) { length += 2; int j = length-1; while(j > i+2) { str[j] = str[j-2]; j--; } str[i] = '%'; str[i+1] = '2'; str[i+2] = '0'; } i--; } }};
0 0
- 空格替换
- 替换空格
- 空格替换
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 空格替换
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 替换空格
- 笔记——Texture Synthesis Using Convolutional Neural Networks (Leon A. Gatys et al)
- 104. Maximum Depth of Binary Tree
- leecode 解题总结:363. Max Sum of Rectangle No Larger Than K
- android中Intent学习笔记
- android studio心得
- 替换空格
- 513. Find Bottom Left Tree Value
- ucosii在stm32上的移植详解2
- RVCT安装
- POJ2253 Frogger
- 【Spring】注解
- 手推机器学习公式(一) —— BP 反向传播算法
- Android-第三方高德定位
- 九度OJ-1010:A + B