48. Rotate Image(第十三周)
来源:互联网 发布:java split函数 参数 编辑:程序博客网 时间:2024/05/29 10:13
class Solution
{
public:
void rotate(vector<vector<int>>& matrix)
{
int n = matrix.size();
for(int i = 0; i < n; i++)
{
for(int j = i + 1; j < n; j++)
{
swap(matrix[i][j],matrix[j][i]);
}
reverse(matrix[i].begin(),matrix[i].end());
}
}
{
public:
void rotate(vector<vector<int>>& matrix)
{
int n = matrix.size();
for(int i = 0; i < n; i++)
{
for(int j = i + 1; j < n; j++)
{
swap(matrix[i][j],matrix[j][i]);
}
reverse(matrix[i].begin(),matrix[i].end());
}
}
};
本题的题意是将矩阵90°顺时针翻转,求翻转后的矩阵。
reverse方法是将一段区间内从头到尾所有元素反向排列,标头是 <algorithm>,参数是.begin()和.end()。
阅读全文
0 0
- 48. Rotate Image(第十三周)
- LeetCode 48. Rotate Image(旋转)
- leetcode 48. Rotate Image(矩阵旋转)
- [LeetCode]48.Rotate Image
- LeetCode 48. Rotate Image
- LeetCode 48.Rotate Image
- LeetCode --- 48. Rotate Image
- [Leetcode] 48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- [leetcode] 48. Rotate Image
- Leetcode 48. Rotate Image
- 48. Rotate Image LeetCode
- [LeetCode]48. Rotate Image
- 48. Rotate Image
- 48. Rotate Image
- mysql 5.7.x改root密码
- 关于Java+Selenium安装及初步设置
- python图表制作
- chkconfig命令 启动或停止 系统服务
- rabbitmq配置镜像模式
- 48. Rotate Image(第十三周)
- 算法作业17
- Java编程思想-21并发
- 算法作业HW14:Leetcode20 Valid Parentheses
- Java编程思想-22图形化用户界面
- ARM-MMU详解
- rabbitmq+haproxy+keepalive实现负载均衡(高可用)
- ActiveMQ(三):ActiveMQ的安全机制、api及订阅模式demo
- 日常踩坑