id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n int global_val = 0;\n for(vector<int> point1 : points){\n map<double, int> mapy;\n for(vector<int> point2 : points){\n if(point1 == point2) continue;\n double y = ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n int ans=0;\n for(auto i:points){\n map<double,int>mp;\n int mx=0,cnt=0,v=0;\n for(auto j:points){\n if(i==j){\n cnt++;\n continue...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "#define pb push_back\n#define ll long long\n#include <bits/stdc++.h>\nusing namespace std;\n\nclass Solution {\npublic:\n\n pair<ll, ll> f(int a, int b) {\n int gcd = __gcd(a, b); // This is Euclid's algorithm\n return {a / gcd, b / gcd}; // Return the reduced form of the fraction\n }...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "struct hash_pair {\n template <class T1, class T2>\n size_t operator()(const pair<T1, T2>& p) const {\n auto hash1 = hash<T1>{}(p.first);\n auto hash2 = hash<T2>{}(p.second);\n return hash1 ^ (hash2 << 1); // Simple combination of the two hash values\n }\n};\n\nclass Solution ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n int n=points.size();\n if(n<=2) return n;\n int ans = 0;\n\n for(auto it1 : points){\n unordered_map<double,int> mp;\n double x1 = it1[0], y1 = it1[1];\n for(auto it2 :...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution \n{\npublic:\n int maxPoints(vector<vector<int>>& points) \n {\n if(points == vector<vector<int>>({{2, 3}, {3, 3}, {-5, 3}}))\n {\n return 3;\n }\n int n = points.size();\n if (n <= 2) return n; \n\n int maxPointsOnLine = 0;\n\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n#define unsigned long long ull\n int gcd(int a, int b) {\n int sign = 1;\n if (a < 0 || b < 0)\n sign = -1;\n a = abs(a), b = abs(b);\n if (a < b)\n swap(a, b);\n while (b) {\n // cout << a << \" \" << b << en...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n#define unsigned long long ull\n int gcd(int a, int b) {\n int sign = 1;\n if (a < 0 || b < 0)\n sign = -1;\n a = abs(a), b = abs(b);\n if (a < b)\n swap(a, b);\n while (b) {\n // cout << a << \" \" << b << en...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "using namespace std;\n\nclass Solution {\npublic:\n function<bool(const pair<double, double>&, const pair<double, double>&)> cmp =\n [](const pair<double, double>& a, const pair<double, double>& b) {\n const double EPS = 1e-9;\n if (fabs(a.first - b.first) < EPS) {\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n float inf = numeric_limits<float>::infinity();\n pair<float, float> getLineParams(vector<int>& p1, vector<int>& p2) {\n if(p1[0] > p2[0])\n return getLineParams(p2, p1);\n float k = p1[0] != p2[0] ? (p1[1] - p2[1]) / float(p1[0] - p2[0]) : inf;\n\n...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int gcd(int a, int b) {\n if (b == 0) return a;\n return gcd(b, a%b);\n }\n int maxPoints(vector<vector<int>>& points) {\n int n = points.size();\n int ans = 0;\n\n for (int i = 0; i < n; i++) {\n int cur = 0;\n m...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n int N = points.size();\n if(N <= 2) return N;\n\n int result = 0;\n for(int i = 0; i < N-1; i++) {\n unordered_map<string, int> slopeMap;\n for(int j = i+1; j < N; j++) {\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n if (points.size() == 1) return 1;\n\n int res = 2;\n //unordered_map<vector<float>, int> lines;\n unordered_map<float, unordered_map<float, vector<vector<int>*>>> lines;\n unordered_map<int, vec...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n int n = points.size();\n if(n==1) return 1;\n unordered_map<int, unordered_map<double, int>> mp;\n for(int i = 0; i < n-1; i++){\n for(int j = i+1; j < n; j++){\n int x1 = ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n double getSlope(vector<int> point1, vector<int> point2) {\n int pt1_x = point1[0];\n int pt1_y = point1[1];\n int pt2_x = point2[0];\n int pt2_y = point2[1];\n double x = pt1_x - pt2_x;\n double y = pt1_y - pt2_y;\n return y/x;...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n double getSlope(vector<int> point1, vector<int> point2) {\n int pt1_x = point1[0];\n int pt1_y = point1[1];\n int pt2_x = point2[0];\n int pt2_y = point2[1];\n double x = pt1_x - pt2_x;\n double y = pt1_y - pt2_y;\n return y/x;...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "struct pair_hash {\n template <class T1, class T2>\n std::size_t operator () (const std::pair<T1,T2> &p) const {\n auto h1 = std::hash<T1>{}(p.first);\n auto h2 = std::hash<T2>{}(p.second);\n\n // Mainly for demonstration purposes, i.e. works but is overly simple\n // In t...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n \n pair<int, int> reduce_frac(int num, int denom) {\n int reduction = __gcd(abs(num), abs(denom));\n int factor = 1;\n if ((num > 0 && denom < 0) || (num < 0 && denom > 0)) {\n factor *= -1;\n }\n num = abs(num) / reduction;\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n if (points.size() <= 1) {\n return points.size();\n }\n\n int maxPoints = 0;\n\n for (int i = 0 ; i < points.size() ; ++i) {\n unordered_map<int, unordered_map<int,int>> m;\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n int n=points.size();\n if(n<3) return n;\n unordered_map<string,set<vector<int>>>count;\n for(int i=0; i<n; i++){\n for(int j=i+1; j<n; j++){\n int dx=points[i][0]-points[j][0...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int gcd(int x, int y) {\n int upper_bound = min(abs(x), abs(y));\n for (int i = upper_bound; i >= 1; --i) {\n if (x % i == 0 && y % i == 0) {\n return i;\n }\n }\n return -1;\n }\n int maxPoints(vector<vec...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(std::vector<std::vector<int>>& points) {\n // line equation y = mx + c\n // m - slope\n // c - intercept\n // c = mx + y\n std::map<std::pair<double, double>, std::set<std::vector<int>>> lines;\n for (int i = 0; i < poin...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(std::vector<std::vector<int>>& points) {\n // line equation y = mx + c\n // m - slope\n // c - intercept\n // c = mx + y\n std::map<std::pair<double, double>, std::set<std::vector<int>>> lines;\n for (int i = 0; i < poin...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n int n = points.size(),res=0,max_p=0;\n for(int i=0;i<n;i++){\n unordered_map<string,unordered_map<string,int>> map;\n int d = 0;\n for(int j=i+1;j<n;j++){\n if(points[...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n int n = points.size(),res=0,max_p=0;\n for(int i=0;i<n;i++){\n unordered_map<string,unordered_map<string,int>> map;\n int d = 0;\n for(int j=i+1;j<n;j++){\n if(points[...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n struct Myhash {\n size_t operator()(const vector<double>& vec) const {\n size_t digest = 0;\n auto f = hash<double>();\n for (const auto& v : vec) {\n size_t v_hash = f(v);\n digest ^= v_hash + 0x9e3779b9 +...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\nprivate:\n int gcd(int a, int b) {\n return b? gcd(b, a%b) : a;\n }\n void fixSign(int &a, int &b) {\n int sa{a >= 0}, sb{b >= 0}, sign{sa^sb? -1 : 1};\n a = abs(a);\n b = sign * abs(b);\n }\npublic:\n int maxPoints(vector<vector<int>>& points) {...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n int n = points.size();\n if(n == 1) return 1;\n int cnt =0;\n for(int i=0; i<n; i++){\n unordered_map<double, set<pair<int,int>>> mp;\n double slope;\n // int size = 0;\...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n map<pair<double,double>,set<int>> m;\n int n=points.size();\n for(int i=0;i<n;i++)\n {\n for(int j=i+1;j<n;j++)\n {\n double y1=points[i][1];\n doubl...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n map<pair<double, double>, set<int>> mm;\n \n int n = points.size();\n int ans = 0;\n map<int,int> m;\n for(auto i:points)\n {\n m[i[0]]++;\n }\n for(auto [...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n int n = points.size();\n map <pair<float, float>, set<pair<int,int>>> m;\n map <int, set<pair<int,int>>> vert;\n for(int i = 0; i < n; i++) {\n for(int j = 0; j < n; j++) {\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n //each pair of points forms a line\n //compute if an nth point is on that line by checking slope between points on that line\n //brute force is then checking the pairwise slopes for all pairs\n unorder...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n //each pair of points forms a line\n //compute if an nth point is on that line by checking slope between points on that line\n //brute force is then checking the pairwise slopes for all pairs\n unorder...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n if (points.size() == 1) {\n return 1;\n }\n\n for (int i = 0; i < points.size(); i++) {\n for (int j = i + 1; j < points.size(); j++) {\n std::string h1 = hash1(points[i],...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\nstruct VectorCompare{\n bool operator()(const vector<int>& a,const vector<int>& b) const{\n if(a[0]==b[0]){\n return a[1]<b[1];\n }\n else{\n return a[0]<b[0];\n }\n }\n};\n int maxPoints(vector<vector<int>>& points) {\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "#define DEBUG 0\n\n// Hash function \nstruct hashFunction \n{ \n size_t operator()(const vector<int> \n &myVector) const \n { \n std::hash<int> hasher; \n size_t answer = 0; \n \n for (int i : myVector) \n { \n answer ^= hasher(i) + 0x9e3779b9 + \n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\nprivate:\n pair<double,double> getkn(vector<int> p1, vector<int> p2){\n double k = (double)(p2[1]-p1[1])/(p2[0]-p1[0]);\n double n = p1[1]-k*p1[0];\n return {k,n};\n }\npublic:\n int maxPoints(vector<vector<int>>& points) {\n if(points.size()==1) retur...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n double get_slope(vector<int> point1, vector<int>point2) {\n if (point1[0] == point2[0])\n return INT_MAX;\n return (point1[1] * 1.0 - point2[1] * 1.0) / (point1[0] * 1.0 - point2[0] * 1.0); \n }\n double get_intercept(vector<int> point1, double ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n map<pair<double, double>, set<vector<int>>> mp;\n for (int i = 0; i < points.size(); i++) {\n for (int j = i + 1; j < points.size(); j++) {\n auto first = points[i];\n auto s...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n \n int m_nMaxPoints = 0;\n\n class SlopeIntercept\n {\n public:\n SlopeIntercept()\n : m_dx(INT_MAX), m_dy(INT_MAX), m_yint(FLT_MAX)\n {}\n\n SlopeIntercept(int dx, int dy, float yint)\n : m_dx(dx), m_dy(dy), m_yint(yint)\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& arr) {\n int n = arr.size();\n if(n == 1) return 1;\n map<vector<float>, unordered_map<int, int>> mp;\n unordered_map<float, unordered_map<int, int>> mpx, mpy;\n for (int i = 0; i < n; i++) {\n f...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n const int n = points.size();\n if(n == 1) return 1;\n \n vector<set<pair<int, int>>> s;\n int maxp = 0;\n for(int i = 0; i < n; i++){\n unordered_map<string, int> m;\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) \n {\n if(points.size()==1) return 1;\n int fin=INT_MIN;\n for(int i=0; i<points.size(); i++)\n {\n unordered_map<float,set<vector<int>>> umap;\n\n for(int j=0; j<points.size(); j+...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n pair<double,double>find_m_c(vector<int>a,vector<int>b)\n {\n if(a[0]==b[0])\n {\n return {a[0],INT_MAX};\n }\n double slope=(a[1]-b[1])/((a[0]-b[0])/1.0);\n double c=a[1]-slope*a[0];\n return {slope,c};\n }\n int m...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n map<pair<double, double>, unordered_set<int>> mm;\n \n int n = points.size();\n int ans = 0;\n map<int,int> m;\n for(auto i:points)\n {\n m[i[0]]++;\n }\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n\n int n = points.size();\n\n if(n == 1){\n return 1;\n }\n \n //(m, c) -> {pair of xys}\n unordered_map<double, unordered_map<double, set<pair<double, double>>>> mcPoints;\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "struct Line {\n int slope_y;\n int slope_x;\n double y_intercept;\n bool operator==(const Line& other) const { return slope_y == other.slope_y && slope_x == other.slope_x && y_intercept == other.y_intercept; }\n};\n\nnamespace std {\n template <>\n struct hash<Line> {\n size_t oper...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "struct Line {\n int slope_y;\n int slope_x;\n double y_intercept;\n bool operator==(const Line& other) const { return slope_y == other.slope_y && slope_x == other.slope_x && y_intercept == other.y_intercept; }\n};\n\nsize_t hash(int a, int b) {\n return std::hash<uint64_t>()(((uint64_t)a << ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "namespace std {\n template <>\n struct hash<pair<double, double>> {\n size_t operator()(const pair<double, double>& line) const {\n return hash<double>()(line.first) ^ hash<double>()(line.second);\n }\n };\n\n template <>\n struct hash<vector<int>> {\n size_t ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& a) {\n int n = a.size();\n\n if(n <= 2) return n;\n\n int mx = 0;\n\n map<pair<double, double>, set<vector<int>>> mp;\n\n for(int i = 0; i < n; i++) {\n for(int j = i+1; j < n; j++) {\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n\n unordered_map< int,unordered_map< double,unordered_set<double>> > b;\n unordered_map<double,unordered_map<double,int>> c;\n\n int n=points.size(),max=2;\n double k,m;\n if (n==1) return 1;\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n\n unordered_map< int,unordered_map< double,unordered_set<double>> > b;\n unordered_map<double,unordered_map<double,int>> c;\n\n int n=points.size(),max=2;\n double k,m;\n if (n==1) return 1;\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& arr) {\n int n = arr.size();\n if(n == 1) return 1;\n map<vector<double>, unordered_map<int, int>> mp;\n unordered_map<double, unordered_map<int, int>> mpx, mpy;\n for (int i = 0; i < n; i++) {\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n\n unordered_map<string, unordered_set<string>> kToPoints;\n int n=points.size();\n if(n<3){\n return n;\n }\n for(int i=0; i<n; i++){\n \n int x1 = points[i][0];...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\nprivate:\n double getM(vector<int> a, vector<int> b){\n if(a[0] == b[0])\n return a[0];\n return (a[1] - b[1])/((a[0] - b[0])/1.0);\n }\n double getC(vector<int> a, vector<int> b, double m){\n if(a[0] == b[0])\n return INT_MAX;\n ...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n pair<double,double> cal_m_c(vector<int> A,vector<int> B){\n if(A[0]==B[0]){\n return {A[0],INT_MAX};\n }\n double m=(A[1]-B[1])/((A[0]-B[0])/1.0);\n double c=A[1]-m*A[0];\n return {m,c};\n }\n int maxPoints(vector<vector<int...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n pair<double,double> cal_m_c(vector<int> A,vector<int> B){\n if(A[0]==B[0]){\n return {A[0],INT_MAX};\n }\n double m=(A[1]-B[1])/((A[0]-B[0])/1.0);\n double c=A[1]-m*A[0];\n return {m,c};\n }\n int maxPoints(vector<vector<int...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n /*if(points.size() == 2){\n if(points[0][0] == points[1][0] || points[0][0] == points[1][1] ){\n return 2;\n }\n if(points[0][1] == points[1][0] || points[0][1] == points[1...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n /*if(points.size() == 2){\n if(points[0][0] == points[1][0] || points[0][0] == points[1][1] ){\n return 2;\n }\n if(points[0][1] == points[1][0] || points[0][1] == points[1...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n /*if(points.size() == 2){\n if(points[0][0] == points[1][0] || points[0][0] == points[1][1] ){\n return 2;\n }\n if(points[0][1] == points[1][0] || points[0][1] == points[1...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n /*if(points.size() == 2){\n if(points[0][0] == points[1][0] || points[0][0] == points[1][1] ){\n return 2;\n }\n if(points[0][1] == points[1][0] || points[0][1] == points[1...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n /*if(points.size() == 2){\n if(points[0][0] == points[1][0] || points[0][0] == points[1][1] ){\n return 2;\n }\n if(points[0][1] == points[1][0] || points[0][1] == points[1...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n /*if(points.size() == 2){\n if(points[0][0] == points[1][0] || points[0][0] == points[1][1] ){\n return 2;\n }\n if(points[0][1] == points[1][0] || points[0][1] == points[1...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n /*if(points.size() == 2){\n if(points[0][0] == points[1][0] || points[0][0] == points[1][1] ){\n return 2;\n }\n if(points[0][1] == points[1][0] || points[0][1] == points[1...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n /*if(points.size() == 2){\n if(points[0][0] == points[1][0] || points[0][0] == points[1][1] ){\n return 2;\n }\n if(points[0][1] == points[1][0] || points[0][1] == points[1...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n /*if(points.size() == 2){\n if(points[0][0] == points[1][0] || points[0][0] == points[1][1] ){\n return 2;\n }\n if(points[0][1] == points[1][0] || points[0][1] == points[1...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\npublic:\n int maxPoints(vector<vector<int>>& points) {\n vector<int > A={2,1}; \n vector<int > B={2,2};\n cal_m_c(A,B);\n if(points.size()<2){\n return points.size();\n }\n map<pair<double,double>,set<vector<int>>> mp;\n for(i...
149
<p>Given an array of <code>points</code> where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code> represents a point on the <strong>X-Y</strong> plane, return <em>the maximum number of points that lie on the same straight line</em>.</p> <p>&nbsp;</p> <p><strong class="example">Example 1:</strong></p> <img alt="" ...
3
{ "code": "class Solution {\n\npublic:\n\n int maxPoints(vector<vector<int>>& points) {\n\n vector<int > A={2,1}; \n\n vector<int > B={2,2};\n\n cal_m_c(A,B);\n\n if(points.size()<2){\n\n return points.size();\n\n }\n\n map<pair<double,double>,set<vector<int>>> ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
0
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n stack<int> my_stack;\n int i = 0;\n for (int i = 0; i < tokens.size(); i++) {\n if (tokens[i] == \"+\") {\n int first_element = my_stack.top();\n my_stack.pop();\n ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
0
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n vector<int> st;\n int op1;\n int op2;\n for (auto token:tokens){\n if (token == \"+\"){\n op2 = st.back();\n st.pop_back();\n op1 = st.back();\n ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
0
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n\n vector<int> operands; // Stack to store operands\n \n for (const string& each : tokens) {\n if (isOperator(each)) {\n // Pop two operands from the stack\n int opr2 = operan...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
0
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n vector<int> stack;\n int temp;\n for(string i : tokens){\n if(i[0] == '+'){\n temp = stack[stack.size()-1] + stack[stack.size()-2];\n stack.pop_back();\n stack...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
0
{ "code": "class Solution {\npublic:\n \n bool check(string c)\n {\n if(c == \"+\")\n return true;\n if(c == \"-\")\n return true;\n if(c == \"*\")\n return true;\n if(c == \"/\")\n return true;\n return false;\n }\n \n i...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
0
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& to) {\n int num=0;\n vector<int> stack;\n for (int i = 0; i < to.size(); i++)\n {\n if(to[i]==\"+\") {num=stack.back()+stack[stack.size()-2];stack.pop_back();stack.pop_back();stack.push_back(num);}\n ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
0
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n vector<int> stack;\n \n for (string& token : tokens) {\n if (token == \"+\" || token == \"-\" || token == \"*\" || token == \"/\") {\n int b = stack.back(); stack.pop_back(); \n ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
0
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n vector<int> stack;\n int temp;\n for(string i : tokens){\n if(i[0] == '+'){\n temp = stack[stack.size()-1] + stack[stack.size()-2];\n stack.pop_back();\n stack...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
0
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n stack<int> st;\n\n for (string c : tokens) {\n if (c == \"+\") {\n int second = st.top(); st.pop();\n int first = st.top(); st.pop();\n st.push(first + second);\n ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
0
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n stack<int>stc;\n for(int i=0;i<tokens.size();i++)\n {\n if(tokens[i]==\"+\")\n {\n int second=stc.top();stc.pop();\n int first=stc.top();stc.pop();\n ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
1
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n stack<int> s;\n for (string str: tokens){\n if(str == \"+\" || str == \"-\" || str == \"/\" || str == \"*\"){\n if(!str.empty()){\n int b = s.top();\n s.pop()...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
1
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n stack<int>st;\n int ans=0;\n for(auto it:tokens){\n\n if(it ==\"+\" || it == \"*\" || it == \"-\" || it ==\"/\"){\n\n if(st.size()<=1){\n continue;\n }\n ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n stack<int> sk;\n for (const string& token : tokens) {\n if (token == \"+\" || token == \"-\" || token == \"*\" || token == \"/\") {\n int num1 = sk.top();\n sk.pop();\n ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& s) {\n stack<int>st;\n map<string,int>mp;\n mp[\"+\"]=1;\n mp[\"-\"]=2;\n mp[\"*\"]=3;\n mp[\"/\"]=4;\n for(int i = 0; i < s.size(); i++) {\n if(mp.find(s[i]) != mp.end()) {\n ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n stack<long long int> s;\n int i = 0;\n while(i < tokens.size()) {\n if(tokens[i] == \"+\") {\n int a = s.top();\n s.pop();\n int b = s.top();\n ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) \n {\n // Postfix Evaluation\n\n // 2 5 + = 7\n // Step 1 String mapped to function\n unordered_map <string,function<long(long,long)>> op\n {\n {\"+\",plus()},\n {\"-\",minus()},\n...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "// Integrantes: Gino Daza Yalta, Nicolas Stigler, Milton Cordova\n\n\ntemplate <typename T>\nclass Stack {\nprivate:\n struct Node {\n T data;\n Node* next;\n Node(T d) : data(d), next(nullptr) {}\n };\n\n Node* topNode;\n\npublic:\n Stack() : topNode(nullptr) {}\n\n ~St...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) \n {\n stack<int> mystack;\n\n const auto is_operator = [&] (const string& t)\n {\n return t == \"+\" || t == \"-\" || t == \"*\" || t == \"/\";\n };\n\n const auto evaluate = [&] (const stri...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n stack<int> st;\n double ans;\n bool start = false;\n for(int i = 0; i < tokens.size(); i++){\n if(st.empty()) st.push(i);\n else if(tokens[i][0] == '+'){\n int temp = stoi...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n stack<int> st;\n double ans;\n bool start = false;\n for(int i = 0; i < tokens.size(); i++){\n if(st.empty()) st.push(i);\n else if(tokens[i][0] == '+'){\n int temp = stoi...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n void calculate(stack<int>& st, string ope) {\n int tmp1 = st.top();\n st.pop();\n int tmp2 =st.top();\n st.pop();\n if (ope==\"+\") {\n st.push(tmp1+tmp2);\n }\n else if (ope==\"-\") {\n st.push(tmp2-tmp1)...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "#include <iostream>\n#include <string>\nclass Solution {\npublic:\n int solve(int a, int b, string o){\n if(o==\"+\") return (a + b);\n else if(o==\"-\") return (a - b);\n else if(o==\"*\") return (a * b);\n else return (a / b);\n }\n int evalRPN(vector<string>& tokens)...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n int solve(int a, int b, string o){\n if(o==\"+\") return (a + b);\n else if(o==\"-\") return (a - b);\n else if(o==\"*\") return (a * b);\n else return (a / b);\n }\n int evalRPN(vector<string>& tokens) {\n if(tokens.size()==1){\n ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "template <typename T>\nclass Node\n{\npublic:\n T val;\n Node* next;\n Node(T value, Node* ptr)\n {\n val = value;\n next = ptr;\n }\n};\n\ntemplate <typename T>\nclass Stack\n{\npublic:\n Stack(T val, Node<T>* ptr)\n {\n dummyHead = new Node<T>(val, ptr);\n }\n...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n\n bool checkint(string s){\n if(s.empty()) return false; \n int start = (s[0] == '-') ? 1 : 0;\n for (int i = start; i < s.length(); ++i) {\n if (!isdigit(s[i])) return false;\n }\n return s.length() > start;\n }\n\n int eva...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\n bool isOperator(string &s) {\n return s == \"+\" || s == \"-\" || s == \"*\" || s == \"/\";\n }\npublic:\n int evalRPN(vector<string>& tokens) {\n vector<string> last;\n for (string t : tokens) {\n if (isOperator(t)) {\n string op2 ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n vector<string> stack;\n for (string x : tokens){\n if (x!= \"+\" & x!= \"-\" & x!= \"*\" & x!= \"/\"){\n stack.push_back(x);\n }\n else {\n int op1 = stoi(stac...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string> &tokens)\n {\n stack<string> RPN;\n for (size_t i = 0; i < tokens.size(); i++)\n {\n string present = tokens[i];\n if (present != \"+\" && present != \"-\" && present != \"*\" && present != \"/\")\n ...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "// 150. Evaluate Reverse Polish Notation\n// https://leetcode.com/problems/evaluate-reverse-polish-notation/description/\n\nclass Solution {\npublic:\n\tbool isOp(string a) {\n\t\treturn a == \"+\" || a == \"-\" || a == \"*\" || a == \"/\";\n\t}\n\n\tint stackAns(vector<string>& tokens) {\n\n\t\tstack<int>...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\n\npublic:\n int evalRPN(vector<string>& tokens) {\n \n stack<string> st;\n for(auto it: tokens) {\n if(it == \"+\" || it == \"-\" || it == \"*\" || it == \"/\") {\n int a = stoi(st.top()); st.pop();\n int b = stoi(st.top())...
150
<p>You are given an array of strings <code>tokens</code> that represents an arithmetic expression in a <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.</p> <p>Evaluate the expression. Return <em>an integer that represents the value of the expression</em>.</p> ...
3
{ "code": "class Solution {\npublic:\n int evalRPN(vector<string>& tokens) {\n stack<string> s;\n for (string& t:tokens) {\n if (isdigit(t[0]) || (t.length()!=1 && isdigit(t[1]))) s.push(t);\n else {\n string b = s.top();\n s.pop();\n ...
3,055
<p>You are given a <strong>binary</strong> string <code>s</code> that contains at least one <code>&#39;1&#39;</code>.</p> <p>You have to <strong>rearrange</strong> the bits in such a way that the resulting binary number is the <strong>maximum odd binary number</strong> that can be created from this combination.</p> <...
0
{ "code": "class Solution {\npublic:\n string maximumOddBinaryNumber(string s) {\n int one = 0;\n for(auto it : s) if(it == '1') one++;\n for(int i=0;i<one-1;i++){\n s[i] = '1';\n }\n for(int i=one-1;i<s.size()-1;i++) s[i] = '0';\n s[s.size()-1] = '1';\n ...