Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.
Example
Given 4 points:,,, (1,2)
(3,6)
(0,0)
(1,3)
.
The maximum number is 3
.
Leecode on the original topic, see my previous blog Invert binary tree flipping two fork trees.
Solution One:
//recursionclassSolution { Public: /** * @param root:a TreeNode, the root of the binary tree * @return: Nothing*/ voidInvertbinarytree (TreeNode *root) { if(!root)return; TreeNode*tmp = root->Left ; Root->left = root->Right ; Root->right =tmp; Invertbinarytree (Root-Left ); Invertbinarytree (Root-Right ); }};
Solution Two:
//non-recursionclassSolution { Public: /** * @param root:a TreeNode, the root of the binary tree * @return: Nothing*/ voidInvertbinarytree (TreeNode *root) { if(!root)return; Queue<TreeNode*>Q; Q.push (root); while(!Q.empty ()) {TreeNode* node =Q.front (); Q.pop (); TreeNode*tmp = node->Left ; Node->left = node->Right ; Node->right =tmp; if(node->left) Q.push (node->Left ); if(node->right) Q.push (node->Right ); } }};
[Lintcode] Invert binary tree flips two forks