Example #1
0
int main(int argc, const char * argv[]) {
    
    Solution solution;
    
    // Problem A
    cout << "Problem A" << endl;
    cout << solution.isAnagram("anagram", "nagaram") << endl;
    
    // Problem B
    cout << "Problem B" << endl;
    int numbers[] = { 3, 30, 34, 5, 9 };
    vector<int> numberVector(numbers, numbers + 5);
    cout << solution.largestNumber(numberVector) << endl;
    
    // Problem C
    cout << "Problem C" << endl;
    vector<vector<int>> matrix = {
        { 1, 3, 5, 7 },
        { 10, 11, 16, 20},
        { 23, 30, 34, 50}
    };
    cout << solution.searchMatrix(matrix, -1) << endl;
    cout << solution.searchMatrix(matrix, 23) << endl;
    cout << solution.searchMatrix(matrix, 20) << endl;
    cout << solution.searchMatrix(matrix, 60) << endl;
    
    
    // Problem D
    cout << "Problem D" << endl;
    vector<int> collection = { 1, 1, 1, 3, 2 };
    vector<vector<int>> result = solution.permute(collection);
    
    for (int i = 0; i < result.size(); i++) {
        for (int j = 0; j < result[i].size(); j++) {
            cout << result[i][j] << " ";
        }
        cout << endl;
    }
    
    // Problem E
    cout << "Problem E" << endl;
    vector<Interval> intervals = { Interval(1, 3), Interval(2, 6), Interval(8, 10), Interval(15, 18) };
    vector<Interval> merged = solution.merge(intervals);
    for (int i = 0; i < merged.size(); i++) {
        cout << "[" << merged[i].start << ", " << merged[i].end << "], ";
        
    }
    
    return 0;
}
Example #2
0
int main() {
    int target = 3;
    int row1a[4] = {1, 3, 5, 7};
    int row2a[4] = {10, 11, 16, 20};
    int row3a[4] = {23, 30, 34, 50};
    vector<int> row1v(row1a, row1a + sizeof(row1a)/sizeof(int));
    vector<int> row2v(row2a, row2a + sizeof(row2a)/sizeof(int));
    vector<int> row3v(row3a, row3a + sizeof(row3a)/sizeof(int));
    vector<vector<int> > matrix;
    matrix.push_back(row1v);
    matrix.push_back(row2v);
    matrix.push_back(row3v); 
    Solution sol;
    cout << "[" << endl;
    for (int i = 0; i < matrix.size(); i++) {
        cout << " [";
        for (int j = 0; j < matrix[i].size(); j++) {
            cout << matrix[i][j] << " ";
        }
        cout << "]" << endl;
    } 
    cout << "]" << endl;
    if(sol.searchMatrix(matrix, target))
        cout << target << " is in the matrix." << endl;
    else
        cout << target << " is NOT in the matrix." << endl;
}
int main(void)
{
    vector<vector<int>> m {{1, 3, 5, 7}, {10, 11, 16, 20}, {23, 30, 34, 50}};
    Solution sol;
    std::cout << sol.searchMatrix(m, 10) << std::endl;
    return 0;
}
int main()
{
    vector<  vector<int> > matrix;

    int m,n;
    cin >> m >> n;
    while(m --)
    {
        int k = n;
        vector<int> row;
        while(k --)
        {
            int val;
            cin >> val;
            row.push_back(val);
        }
        matrix.push_back(row);
    }

    int target;
    cin >> target;

    Solution sol;
    cout << sol.searchMatrix(matrix, target) << endl;
    return 0;

}
// [
//   [1,   3,  5,  7],
//   [10, 11, 16, 20],
//   [23, 30, 34, 50]
// ]
int main(int argc, char **argv) {
    vector<vector<int> >matrix;
    vector<int> tmp;
    tmp.push_back(1);
    tmp.push_back(3);
    tmp.push_back(5);
    tmp.push_back(7);
    matrix.push_back(tmp);
    tmp.clear();
    tmp.push_back(10);
    tmp.push_back(11);
    tmp.push_back(16);
    tmp.push_back(20);
    matrix.push_back(tmp);
    tmp.clear();
    tmp.push_back(23);
    tmp.push_back(30);
    tmp.push_back(34);
    tmp.push_back(50);
    matrix.push_back(tmp);

    Solution sol;
    cout<<sol.searchMatrix(matrix, 50)<<endl;

    return 0;
}
Example #6
0
int main(){
	vector<vector<int> > matrix = { { 1, 1 }, { 3, 3 } };

	Solution s;
	cout << (s.searchMatrix(matrix, 2)?"T":"F");
	return 0;
}
Example #7
0
int main()
{
	Solution s ;
	vector<vector<int>> matrix;
	vector<int> v1;
	vector<int> v2;
	vector<int> v3;

	v1.push_back(1);
	v1.push_back(3);
	v1.push_back(5);
	v1.push_back(7);
	
	v2.push_back(10);
	v2.push_back(11);
	v2.push_back(16);
	v2.push_back(20);

	v3.push_back(23);
	v3.push_back(30);
	v3.push_back(34);
	v3.push_back(50);

	matrix.push_back(v1);
	matrix.push_back(v2);
	matrix.push_back(v3);

	if(s.searchMatrix(matrix, 9))
		cout << "true" << endl;
	else cout << "false" << endl;

	system("pause");
	return 1;

}
int main(){
	vector<vector<int> > A;
	int target = 1;
	Solution sol;
	cout<<"Result is: " << sol.searchMatrix(A, target)<<endl;
	return 0;
}
static bool doTest(Matrix matrix)
{
    std::priority_queue<int> nums;
    for (auto &row : matrix)
        std::for_each(row.cbegin(), row.cend(), [&nums](const int &num) { nums.push(num); });

    if (nums.empty())
        return false;

    Solution solution;
    auto num = nums.top();
    while (!nums.empty())
    {
        bool contains = (num == nums.top());
        bool val = solution.searchMatrix(matrix, num);
        if (val != contains)
            return false;

        if (contains)
            nums.pop();

        --num;
    }

    return true;
}
Example #10
0
int main() {
  Solution sol;
  vector<int> row1 {1,   3,  5,  7};
  vector<int> row2 {10, 11, 16, 20};
  vector<int> row3 {23, 30, 34, 50};
  vector<vector<int> > matrix {row1, row2, row3};
  cout << sol.searchMatrix(matrix, 1) << endl;
}
Example #11
0
int main() {
    Solution sol;
    vector<vector<int>> mat = {{1,3,5,7},
                               {10,11,16,20},
                               {23,30,34,50}};
    cout << (true == sol.searchMatrix(mat, 11));
    cout << endl;
}
Example #12
0
int main() {
    vector< vector<int> > matrix(1, vector<int>(2, 0));
    matrix[0][0] = -1;
    matrix[0][1] = 3;
    Solution sol;
    int res = sol.searchMatrix(matrix, 1);
    return 0;
}
Example #13
0
int main()
{
	vector<vector<int>> M = { {1,   3,  5,  7},
				  {10, 11, 16, 20},
				  {23, 30, 34, 50} };
	Solution s;
	cout << s.searchMatrix(M, 16) << endl;
        return 0;
}
int main(){
    Solution s;
    vector<vector<int>> matrix = {{1,   3,  5,  7},
                                  {10, 11, 16, 20},
                                  {23, 30, 34, 50}};

    cout << "res: " << s.searchMatrix(matrix, 10) << endl;

}
Example #15
0
int main() {
    vector<vector<int>> matrix = {{1, 3, 5, 7},
                                  {10, 11, 16, 20},
                                  {23, 25, 30, 34},
                                  {37, 38, 45, 50}};
//    vector<vector<int>> matrix = {{1}};
    Solution sln = Solution();
    for (int i = 0; i < 60; i++)
        cout << i << ": " << sln.searchMatrix(matrix, i) << endl;
}
Example #16
0
int main()
{
    vector<vector<int> >test;
    vector<int> test1;
    test1.push_back(1);
    test1.push_back(1);
    test.push_back(test1);
    Solution s;
    cout<<s.searchMatrix(test,0)<<endl;
    return 0;
}
Example #17
0
int main(int argc, char *argv[]) {
    vector<int> e1, e2;
    e1.push_back(1);
    e2.push_back(3);
    vector<vector<int> > a;
    a.push_back(e1);
    a.push_back(e2);
    Solution k;
    cout << k.searchMatrix(a, 3);
    return 0;
}
Example #18
0
int main()
{
    Solution s;
    bool ret;
    vector<vector<int>> matrix = {{1}, {3}};
    //vector<vector<int>> matrix = {{1,3,5,7},{10,11,16,20},{23,30,34,50}};

    ret = s.searchMatrix(matrix, 1);
    cout << ret << endl;

    return 0;
}
Example #19
0
int main() {
    Solution sol;

    {
        vector<vector<int> > p0 = {
            {1,   3,  5,  7},
            {10, 11, 16, 20},
            {23, 30, 34, 50}
        };
        cout << sol.searchMatrix(p0, 3) << endl;
    }

    return 0;
}
void main(){
    vector<vector<int>> mat;
    int i1[] = {1,   3,  5,  7};
    vector<int> v1 (i1, i1 + sizeof(i1)/sizeof(int));
    mat.push_back(v1);
    int i2[] = {10, 11, 16, 20};
    vector<int> v2 (i2, i2 + sizeof(i2)/sizeof(int));
    mat.push_back(v2);
    int i3[] = {23, 30, 34, 50};
    vector<int> v3 (i2, i2 + sizeof(i3)/sizeof(int));
    mat.push_back(v3);
    Solution sol;
    bool b = sol.searchMatrix(mat,10);
}
Example #21
0
int main()
{

    vector<vector<int>> matrix={
  {1,   4,  7, 11, 15},
  {2,   5,  8, 12, 19},
  {3,   6,  9, 16, 22},
  {10, 13, 14, 17, 24},
  {18, 21, 23, 26, 30}
};
  matrix={{2}};
  Solution solve;
  cout<<solve.searchMatrix(matrix,2);
    return 0;
}
Example #22
0
int main() {
  std::vector<std::vector<int>> m = {
    {1, 4, 7, 11, 15},
    {2, 5, 8, 12, 19},
    {3, 6, 9, 16, 22},
    {10, 13, 14, 17, 24},
    {18, 21, 23, 26, 30},
  };
  int t = 20;
  
  Solution s;
  printf("%s\n", s.searchMatrix(m, t) ? "true" : "false");
  
  return 0;
}
Example #23
0
int main()
{
	Solution t;
	vector<vector<int>>ma;
	vector<int>row1;
	vector<int>row2;
	vector<int>row3;
	row1.push_back(1);
	row2.push_back(3);
	row3.push_back(5);
	ma.push_back(row1);
	ma.push_back(row2);
	//ma.push_back(row3);
	cout<<t.searchMatrix(ma,3);
}
int main() {
  Solution s;

  int a1[] = {5};
  int a2[] = {6};
  vector<int> n1(a1,a1+sizeof(a1)/sizeof(int));
  vector<int> n2(a2,a2+sizeof(a2)/sizeof(int));

  vector<vector<int> > m;
  m.push_back(n1);
  m.push_back(n2);
  
  cout << std::boolalpha << s.searchMatrix(m, 6) << endl;

  return 0;
}
Example #25
0
int _tmain(int argc, _TCHAR* argv[])
{
	vector<vector<int>> input;
	

	int in0[] = {-10,-8,-6,-4,-3};
	input.push_back(vector<int>(in0, in0+5));
	int in1[] = {0,2,3,4,5};
	input.push_back(vector<int>(in1, in1+5));
	int in2[] = {8,9,10,10,12};
	input.push_back(vector<int>(in2, in2+5));

	Solution s;
	s.searchMatrix(input, 0);
	return 0;
}
Example #26
0
int _tmain(int argc, _TCHAR* argv[])
{
	vector<vector<int>> matrix =
	{ 
		{ 1, 2, 3, 7, 8 }, 
		{ 5, 10, 14, 16, 19 }, 
		{ 8, 10, 18, 19, 23 }, 
		{9, 12, 22, 24, 29}
	};
	Solution a;
	if (a.searchMatrix(matrix, 14)){
		cout << "true" << endl;
	}
	else
		cout << "error" << endl;
	return 0;
}
Example #27
0
int main(){

  Solution sol;
  vector<vector<int> > A;
  A.resize(5);
  for (int i = 0 ; i < 5; i++)
  {
    A[i].resize(5);
    for (int j = 0; j < 5; j++)
    {
     A[i][j] = 5 * i + j; 
    }
  }

  leettest(sol.searchMatrix(A, 15));

  return 0;
}
int main()
{
    vector<vector<int>> matrix;
    vector<int> line;
	line.push_back(1);
	line.push_back(3);
	line.push_back(5);
	line.push_back(7);
	matrix.push_back(line);

	Solution_v1 slt_v1;
    int target = 0;
	bool rslt_v1 = slt_v1.searchMatrix_space_O_1(matrix, target);
	Solution slt;

    bool rslt = slt.searchMatrix(matrix, target);
	return 0;
}
	void test() {
		vector<vector<int>> matrix;
		vector<int> row0, row1, row2;
		row0.push_back(1);
		row0.push_back(4);
		row0.push_back(7);
		row1.push_back(2);
		row1.push_back(5);
		row1.push_back(8);
		row2.push_back(3);
		row2.push_back(6);
		row2.push_back(9);
		matrix.push_back(row0);
		matrix.push_back(row1);
		matrix.push_back(row2);
		Solution so;
		cout << "N240Search2DMtrxII:\t" << so.searchMatrix(matrix, 6) << endl;
	}
int main()
{
	Solution sol;
	//vector<vector<int>> matrix = { 
	//	{ 1, 4, 7, 11, 15 },
	//	{ 2, 5, 8, 12, 19 },
	//	{ 3, 6, 9, 16, 22 },
	//	{ 10, 13, 14, 17, 24 },
	//	{ 18, 21, 23, 26, 30 } 
	//};
	//
	//int target = 5;
	//cout << sol.searchMatrix(matrix, target) << endl;
	vector<vector<int>> matrix = { { -5 } };
	auto target = -5;
	cout << sol.searchMatrix(matrix, target);
	cin.get(); 
	return 0;
}