Not very hard to figure out the solution: splitting the list into 2 halves; reverse the 2nd half and interleave the two halves.But it takes some time ...
分类:
其他好文 时间:
2014-07-18 14:35:09
阅读次数:
214
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +, -, *, /.
Each operand may be an integer or another expression.
Some examples:
["2", "1", ...
分类:
其他好文 时间:
2014-07-18 11:19:56
阅读次数:
210
Reverse IntegerReverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321click to show spoilers.Have you thought about th...
分类:
其他好文 时间:
2014-07-18 09:34:59
阅读次数:
212
Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No...
分类:
其他好文 时间:
2014-07-18 00:32:24
阅读次数:
271
题目:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".要求:1)首尾有空格的时候,反转后的string要将空...
分类:
其他好文 时间:
2014-07-16 19:29:54
阅读次数:
234
class Solution {public: void reverseWords(string &s) { int len = s.length(); if(len == 0) return; vector res; ...
分类:
其他好文 时间:
2014-07-16 18:50:12
阅读次数:
161
Problem: Implement a function to check if a singly linked list is a palindrome.思路:最简单的方法是 Reverse and compare.另外一种非常经典的办法是用 Recursive 的思路,把一个list看成这种形...
分类:
其他好文 时间:
2014-07-16 17:41:23
阅读次数:
188
比如我想将 “javascript”反转为 “tpircsavaj”。我们一般处理都是用for循环然后用StringBuffer一个字符一个字符添加。
其实StringBuffer提供了一个reverse方法就可以实现。测试代码如下:
package com.evan;
public class ReverseTest {
public static void main(String[]...
分类:
编程语言 时间:
2014-07-16 17:19:54
阅读次数:
202
/*
调用方式:add(a, b);
返回类型:string
*/
string add(string a, string b)
{
string s;
reverse(a.begin(), a.end());
reverse(b.begin(), b.end());
int i = 0;
int m, k = 0;
while(a[i] && b...
分类:
其他好文 时间:
2014-07-16 08:04:51
阅读次数:
368
原list: ( ( 1 2 ) ( 3 4 ) )
转置: ( ( 3 4 ) ( 1 2 ) )
深度转置: ( ( 4 3 ) ( 2 1 ) )
( define tree ( list 1 ( list 2 ( list 3 4 ) 5 ) ( list 6 7 ) ) )
( define nil '() )
( define ( my-reverse items...
分类:
其他好文 时间:
2014-07-14 13:04:42
阅读次数:
170