如何实现字符串倒置呢,直接用头尾两个指针从两边向中间扫,并且不断交换两个指针的内容,
void reverse(int a[], int n){
if(n < 2) return;
for(int i = 0; i <= n;)
swap(a[i++], a[--n]);
}
然后,如果要实现字符串反转呢,比如,有字符串abcdefg,假设要将前n个字符与剩下的字符串交换位置...
分类:
编程语言 时间:
2015-03-17 00:54:17
阅读次数:
202
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110...
分类:
其他好文 时间:
2015-03-16 23:16:55
阅读次数:
331
class Solution {public: int reverse(int x) { int flag = 1; long long x1 = x; if(x1 0 && result > 2147483647) return 0; ...
分类:
其他好文 时间:
2015-03-16 20:55:58
阅读次数:
108
Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110010...
分类:
编程语言 时间:
2015-03-16 14:40:54
阅读次数:
156
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321...
分类:
其他好文 时间:
2015-03-15 09:26:45
阅读次数:
99
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link...
分类:
其他好文 时间:
2015-03-15 07:06:35
阅读次数:
100
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return...
分类:
其他好文 时间:
2015-03-14 22:59:56
阅读次数:
243
递归实现reverse_string(char * string)函数。
翻转 原来的字符串
是改变
不是打印出来。
/*
编写一个函数reverse_string(char * string)(递归实现)
实现:将参数字符串中的字符反向排列。
要求:不能使用C函数库中的字符串操作函数。
*/
#include
void reverse_string(char * string...
分类:
编程语言 时间:
2015-03-14 16:58:40
阅读次数:
153
编写一个函数reverse_string(char * string)(递归实现)
实现:将参数字符串中的字符反向排列。
要求:不能使用C函数库中的字符串操作函数。...
分类:
其他好文 时间:
2015-03-14 16:54:57
阅读次数:
151
Reverse Bits问题:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as000000101001010000011110100...
分类:
其他好文 时间:
2015-03-14 16:42:44
阅读次数:
114