Skip to content

Commit

Permalink
1037 added.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyubobobo committed May 19, 2019
1 parent 2c4ec28 commit 47b176e
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 1037-Valid-Boomerang/cpp-1037/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.14)
project(A)

set(CMAKE_CXX_STANDARD 14)

add_executable(A main2.cpp)
47 changes: 47 additions & 0 deletions 1037-Valid-Boomerang/cpp-1037/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/// Source : https://leetcode.com/problems/valid-boomerang/
/// Author : liuyubobobo
/// Time : 2019-05-04

#include <iostream>
#include <vector>

using namespace std;


/// Calculate Slope
/// Time Compelxity: O(1)
/// Space Complexity: O(1)
class Solution {
public:
bool isBoomerang(vector<vector<int>>& points) {

if(points[0] == points[1] || points[1] == points[2])
return false;

int a = points[1][0] - points[0][0], c = points[2][0] - points[1][0],
b = points[1][1] - points[0][1], d = points[2][1] - points[1][1];
return a * d != b * c;
}
};


int main() {

vector<vector<int>> points1 = {{1, 1}, {2, 3}, {3, 2}};
cout << Solution().isBoomerang(points1) << endl;
// true

vector<vector<int>> points2 = {{1, 1}, {2, 2}, {3, 3}};
cout << Solution().isBoomerang(points2) << endl;
// false

vector<vector<int>> points3 = {{0, 0}, {1, 1}, {1, 1}};
cout << Solution().isBoomerang(points3) << endl;
// false

vector<vector<int>> points4 = {{80, 32}, {46, 32}, {59, 32}};
cout << Solution().isBoomerang(points3) << endl;
// false

return 0;
}
43 changes: 43 additions & 0 deletions 1037-Valid-Boomerang/cpp-1037/main2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/// Source : https://leetcode.com/problems/valid-boomerang/
/// Author : liuyubobobo
/// Time : 2019-05-18

#include <iostream>
#include <vector>

using namespace std;


/// Calculate Cross Multiplication
/// Time Compelxity: O(1)
/// Space Complexity: O(1)
class Solution {
public:
bool isBoomerang(vector<vector<int>>& p) {
int a = p[1][0] - p[0][0], b = p[1][1] - p[0][1],
c = p[2][0] - p[1][0], d = p[2][1] - p[1][1];
return a * d - b * c != 0;
}
};


int main() {

vector<vector<int>> points1 = {{1, 1}, {2, 3}, {3, 2}};
cout << Solution().isBoomerang(points1) << endl;
// true

vector<vector<int>> points2 = {{1, 1}, {2, 2}, {3, 3}};
cout << Solution().isBoomerang(points2) << endl;
// false

vector<vector<int>> points3 = {{0, 0}, {1, 1}, {1, 1}};
cout << Solution().isBoomerang(points3) << endl;
// false

vector<vector<int>> points4 = {{80, 32}, {46, 32}, {59, 32}};
cout << Solution().isBoomerang(points3) << endl;
// false

return 0;
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,5 @@ email: [[email protected]](mailto:[email protected])
| 1034 | [Coloring A Border](https://leetcode.com/problems/coloring-a-border/) | [] | [C++](1034-Coloring-A-Border/cpp-1034/) | | |
| 1035 | [Uncrossed Lines](https://leetcode.com/problems/uncrossed-lines/) | [] | [C++](1035-Uncrossed-Lines/cpp-1035/) | | |
| 1036 | [Escape a Large Maze](https://leetcode.com/problems/escape-a-large-maze/) | [] | [C++](1036-Escape-a-Large-Maze/cpp-1036/) | | |
| 1037 | [Valid Boomerang](https://leetcode.com/problems/valid-boomerang/) | [] | [C++](1037-Valid-Boomerang/cpp-1037/) | | |
| | | | | | |

0 comments on commit 47b176e

Please sign in to comment.