去除字符串中的空格
2016-03-21 22:28
274 查看
去除字符串中的空格,并返回修改后的字符串。
要求时间复杂度O(N),空间复杂度O(1)。
要求时间复杂度O(N),空间复杂度O(1)。
#include "stdafx.h" #include <process.h> #include <iostream> using namespace std; void DeleteSpace(char* pStr) { int j = 0; for (int i=0; pStr[i]!='\0'; i++) { if (pStr[i] != ' ') { if (i != j) { pStr[j] = pStr[i]; } j++; } } pStr[j++] = '\0'; } int _tmain(int argc, _TCHAR* argv[]) { char str[] = "Hello w o rl d !"; cout << "Before: " << str << endl; DeleteSpace(str); cout << "After: " << str << endl; system("pause"); return 0; }
相关文章推荐
- 浏览器兼容性问题汇总及解决方案
- 前端工程师切图技能——PS工具准备
- ExtJs布局之border
- wc 统计程序
- 构建之法(前三章)读后感
- Highchart URL
- ZBarSDK
- 完整java开发中JDBC连接数据库代码和步骤
- 设计模式之状态模式
- House Robber III
- D14
- remount of system failed: Read-only file system remount failed 解决方案
- AndroidDevTools
- 常见命令(个人补充ing)
- 001. LeetCode | Pow(x, n)
- 简单绘制了一个绘制invalidate流程
- H5学习_番外篇_PHP入门指南
- 《构建之法》前三章的读后感
- HDU5649 DZY Loves Sorting 线段树
- dijkstra 算法的java实现