字符串的大数乘法,模拟题 把两个字符串倒过来以后对应位置相乘,注意最终结果要去掉最前面的0 class Solution {public: string multiply(string num1, string num2) { reverse(num1.begin(), num1.end()); r...
分类:
其他好文 时间:
2015-03-31 17:37:02
阅读次数:
148
题目:
Given an input string, reverse the string word by word.For example,
Given s = “the sky is blue”,
return “blue is sky the”. 思路一:
先休整下给定的字符串,去掉其中的多于一个的空格,就是使所有单词之间的空格都变成一个,然后去掉最后面的空格,给最前面加一个空格。这...
分类:
其他好文 时间:
2015-03-31 16:08:55
阅读次数:
178
类似这样的后缀表达式:叫做逆波兰表达式["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9["4", "13", "5", "/", "+"] -> (4 + (5 / 13)) -> 4编译器比较喜欢从栈(stack)里面pop两个对象出来计算然后继续pu...
分类:
其他好文 时间:
2015-03-30 13:02:30
阅读次数:
144
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321这个题目的难度在于处理溢出先贴出正确运行的代码:int reverse(int x) { if(x == 0) r...
分类:
其他好文 时间:
2015-03-30 10:47:00
阅读次数:
183
Given an input string, reverse the string word by word.
For example,
Given s = "the sky is blue",
return "blue is sky the".
Update (2015-02-12):
For C programmers: Try to solve it in-place in...
分类:
编程语言 时间:
2015-03-30 09:24:11
阅读次数:
168
两种操作都是递归实现,汉诺塔思想。#include
#include
using namespace std;void reverse(stack &s)//逆序栈
{
if(s.size()==0)
return ;
int a=s.top();
s.pop();
if(s.size()==0)
{...
分类:
编程语言 时间:
2015-03-29 21:01:09
阅读次数:
247
题目链接:evaluate-reverse-polish-notation
import java.util.Stack;
/**
*
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +, -, *, /. Each opera...
分类:
其他好文 时间:
2015-03-28 15:51:06
阅读次数:
130
题目:2.2.2 Reverse Linked List IIReverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->nullptr, m = 2 and n = 4,return 1->4->3->2->5->nullptr.Note: ...
分类:
其他好文 时间:
2015-03-28 11:33:15
阅读次数:
154
题目分析:常规解法,实在不知道如何优化了。 1 class Solution { 2 public: 3 uint32_t reverseBits(uint32_t n) 4 { 5 uint32_t m = 0; 6 for (uint32_t i...
分类:
其他好文 时间:
2015-03-28 11:20:17
阅读次数:
101
1 题目:2.2.1 Add Two NumbersYou 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 numbe...
分类:
其他好文 时间:
2015-03-28 08:48:00
阅读次数:
185