Showing posts with label Math. Show all posts
Showing posts with label Math. Show all posts

Thursday, January 2, 2014

[LeetCode] Valid Number

Link : Valid Number
Validate if a given string is numeric.

Some examples:
"0" => true
" 0.1 " => true
"abc" => false
"1 a" => false
"2e10" => true
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.

Analysis:
Test case is quite important.
To make clear what if input is NULL, '\0', or "    "(only space).
exponential part is quite important.

I tried several times, and there is always some case that I didn't expect.
This is intentionally a vague problem. So ask for details from interviewers, if possible.

Monday, December 30, 2013

[LeetCode] Trapping Rain Water

Link : Trapping Rain Water




Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.

For example,
Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for contributing this image!

Hi GEEKs, bored with LeetCode? Look at this!

The beauty of combination, Math & Algorithm

http://projecteuler.net/