leetcoe.557 Reverse Words in a String III
来源:互联网 发布:php虚拟物品商城 编辑:程序博客网 时间:2024/06/16 11:10
Question
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:
Input: "Let's take LeetCode contest"Output: "s'teL ekat edoCteeL tsetnoc"
Note: In the string, each word is separated by single space and there will not be any extra space in the string.
Solution
reverse 异或交换
void reverse(int b, int e, char *s) { while (b < e) { s[b] = s[b] ^ s[e]; s[e] = s[b] ^ s[e]; s[b] = s[b] ^ s[e]; b++; e--; }}char* reverseWords(char* s) { int i, s_len = strlen(s), index = 0; for (i = 0; i <= s_len; i++) { if (s[i] == ' ' || s[i] == '\0') { reverse(index, i - 1, s); index = i + 1; } } return s;}
阅读全文
0 0
- leetcoe.557 Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- leetocde557: Reverse Words in a String III
- oj557. Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- 557. Reverse Words in a String III
- SlideCutListView左右划删除的list
- 使用siege进行web压力测试
- (132)可移动光源
- mybatis 中sql语句传递多个参数
- springboot集成mybatis
- leetcoe.557 Reverse Words in a String III
- Android编译时报错:Ensure that you have installed a JDK(not just a JRE)and configured your JAVA_HOME......
- SwipeRefrshLayout+RecyclerView实现刷新功能
- [Unity3D] Optimization – Make Atlas textures for ParticleSystem, reduce drawcall, why not ?
- [RK3288][Android6.0] 调试笔记 --- Volume up键改成Back键
- 数据库主键生成方式分析
- SQA度量
- 安卓apk加密,几维安全帮你及时规避app潜在风险
- 在比较对象的时候为什么要重写equls()与hashCode()方法