leetcode刷题.1030. 距离顺序排列矩阵单元格.每日打卡

博客内容仅提及了代码,但无更多关键信息,无法提供更详细摘要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码:

class Solution1030_easy {
public:
	struct Point {
		Point(int x, int y) : x_(x), y_(y) {
		}
		int x_;
		int y_;
	};
	vector<vector<int>> allCellsDistOrder(int R, int C, int r0, int c0) {

		vector<vector<int>> dirs{ {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
		vector<vector<int>> output;
		vector<vector<int>> byteMap(R, vector<int>(C, 0));
		queue<Point> q;
		q.push(Point(r0, c0));
		byteMap[r0][c0] = 1;

		while (q.size()) {
			Point pt = q.front();
			q.pop();
			output.push_back(vector<int>{pt.x_, pt.y_});

			for (int i = 0; i < 4; i++) {
				int x = pt.x_ + dirs[i][0];
				int y = pt.y_ + dirs[i][1];

				if (x < R && y < C && x >= 0 && y >= 0 && !byteMap[x][y]) {

					q.push(Point(x, y));
					byteMap[x][y] = 1;
				}
			}		
		}
		return output;
	}
};

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值