码迷,mamicode.com
首页 > 其他好文 > 详细

牛客网-《剑指offer》-替换空格

时间:2016-01-07 18:21:00      阅读:436      评论:0      收藏:0      [点我收藏+]

标签:

C++

 1 class Solution {
 2 public:
 3     void replaceSpace(char *str,int len) {
 4         int cnt = 0;
 5         for (int i = 0; i < len; i++) {
 6             if (str[i] ==  ) cnt++;
 7         }
 8         int idx = len + cnt * 2 - 1;
 9         for (int i = len - 1; i >= 0; i--) {
10             if (str[i] ==  ) {
11                 str[idx--] = 0;
12                 str[idx--] = 2;
13                 str[idx--] = %;
14             } else {
15                 str[idx--] = str[i];
16             }
17         }
18     }
19 };

 

牛客网-《剑指offer》-替换空格

标签:

原文地址:http://www.cnblogs.com/CheeseZH/p/5110544.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!