Skip to content

Commit 719d0fe

Browse files
Merge pull request #587 from GaurishIIITNR/main
Added Leetcode Problem 154
2 parents 2619e67 + 5e20581 commit 719d0fe

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution
2+
{
3+
public:
4+
int findMin(vector<int> &nums)
5+
{
6+
set<int> st(nums.begin(), nums.end());
7+
vector<int> v(st.begin(), st.end());
8+
// predicate nums[x]>=nums[0] /// tttttffffff aim--> finding first f
9+
int low = 0, high = v.size() - 1;
10+
while (low < high)
11+
{
12+
int mid = low + (high - low) / 2;
13+
if (v[mid] >= v[0])
14+
low = mid + 1;
15+
else
16+
high = mid;
17+
}
18+
// turn low;
19+
return min(v[0], v[low]);
20+
}
21+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution
2+
{
3+
public:
4+
bool searchMatrix(vector<vector<int>> &matrix, int target)
5+
{
6+
int j = matrix[0].size() - 1, i = 0;
7+
while (1)
8+
{
9+
if (j < 0 || i > matrix.size() - 1)
10+
return 0;
11+
if (matrix[i][j] > target)
12+
j--;
13+
else if (matrix[i][j] < target)
14+
i++;
15+
else
16+
return 1;
17+
}
18+
if (matrix[i][j] == target)
19+
return 1;
20+
return 0;
21+
}
22+
};

0 commit comments

Comments
 (0)