My Blog List

Leetcode Blogger

Analysis

  • Brief description of programming will be showed
  • Trifles needed to be noticed such as input empty string, input null pointer, edge conditions which should be considered and clarify

Note

  • Optimized formatted code or method for specific problem needs to be gains
  • usage of programming languages or tools

Code

  • paste the source code from gist.github

[Leetcode Solution] Max Points on a Line



Analysis

  • Firstly find out the identical points and count the number of each distinct point. Enumerate all the lines consisted of two distinct points. Count the number of points lays on this line and return the maximum number.
  • Duplicated points might occur
  • The number of distinct point might less then 3

Note

  • How to check if three points lie on the same line  
Second Version At Leetcode Pass 2
  • How to check if three nodes stand in a line taking into consideration that it might be a line parallel to the coordinate axis
(a.y-b.y)*(b.x-c.x) == (a.x-b.x)*(b.y-c.y) 

  • How to use user defined structure in std::hash by define comparison class by overload ( ) operator. 

Code



Second Version At Leetcode Pass 2

UPDATED AT LEETCODE 2ND PASS

[Leetcode Solution] Evaluate Reverse Polish Notation

Note

  • Vector might be empty
  • Number might be negative

Code




C++ Std::string


  • Constructor


Can take another single string or c-string as parameter. Giving the number of consecutive copies if taking a character.

  • Modifier
All of the string, c-string and single character can be used as operand.


[Leetcode Solution] Reverse Words in a String

Long time no coding, each line needs a cplusplus.com look up : (

Analysis

Programming is straightforward. Extract words from input string using space as delimiter. Write words back to input string in reverse order.

Code

http://fmarss.blogspot.com/2014/10/divide-array-into-sub-arrays.html 


Coding Note

  • Clarification is very important during the interview (Yu's Coding). Make sure following trifles such as 
    1. what's the delimiter
    2. only lower case letters included?
    3. leading trailing or multiple space contained?
    4. empty string input?
Divide an array by given delimiter and perform calculation on each sub array. Code Template can be found here