作者归档:在线疯狂

RSS feed of 在线疯狂

浮点精度问题简析

Why don’t my numbers add up?

为什么我的数加起来对不上?

So you’ve written some absurdly simple code, say for example:

你写了一段极其简单的代码,比如:

    0.1 + 0.2

and got a really unexpected result:

然后得到了一个意想不到的结果:

    0.30000000000000004

Why don’t my numbers, like 0 ...

继续阅读

[LeetCode]Basic Calculator II

题目描述:

Implement a basic calculator to evaluate a simple expression string.

The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should truncate toward zero.

You may assume that the given expression is always valid.

Some ...

继续阅读

[LeetCode]Implement Stack using Queues

题目描述:

Implement the following operations of a stack using queues.

push(x) -- Push element x onto stack.
pop() -- Removes the element on top of the stack.
top() -- Get the top element.
empty() -- Return whether the stack is empty.

Notes:
You ...

继续阅读

[LeetCode]Basic Calculator

题目描述:

Implement a basic calculator to evaluate a simple expression string.

The expression string may contain open ( and closing parentheses ), the plus + or minus sign -, non-negative integers and empty spaces .

You may assume that the given expression is always valid ...

继续阅读