Skip to content

Commit 1246dc7

Browse files
committed
Added Leetcode Problem 48 Name: Rotate Image(Medium) Url:https://leetcode.com/problems/rotate-image
1 parent 5e20581 commit 1246dc7

File tree

2 files changed

+45
-21
lines changed

2 files changed

+45
-21
lines changed
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +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-
}
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+
}
2222
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution
2+
{
3+
public:
4+
void rotate(vector<vector<int>> &mt)
5+
{
6+
int n = mt.size();
7+
int tmp = 0;
8+
for (int i = 0; i < n; i++)
9+
{
10+
for (int j = tmp; j < n; j++)
11+
{
12+
swap(mt[i][j], mt[j][i]);
13+
}
14+
tmp++;
15+
}
16+
for (int i = 0; i < n; i++)
17+
{
18+
for (int j = 0; j < (n / 2); j++)
19+
{
20+
swap(mt[i][j], mt[i][n - j - 1]);
21+
}
22+
}
23+
}
24+
};

0 commit comments

Comments
 (0)