#include <leetcode.h>
|
static int | openLock (vector< string > &deadends, const string &target) |
|
◆ openLock()
int leetcode::open_the_lock::Solution::openLock |
( |
vector< string > & |
deadends, |
|
|
const string & |
target |
|
) |
| |
|
static |
在文件 leetcode.cpp 第 8059 行定义.
8060 unordered_set<string> deads;
8061 unordered_set<string> vis;
8062 for(
auto &deadend: deadends) {
8063 deads.insert(deadend);
8065 auto get_nexts = [](
const string &code) {
8066 vector ans(8, code);
8067 ans[0][0] = (ans[0][0] -
'0' + 10 + 1) % 10 +
'0';
8068 ans[1][0] = (ans[1][0] -
'0' + 10 - 1) % 10 +
'0';
8069 ans[2][1] = (ans[2][1] -
'0' + 10 + 1) % 10 +
'0';
8070 ans[3][1] = (ans[3][1] -
'0' + 10 - 1) % 10 +
'0';
8071 ans[4][2] = (ans[4][2] -
'0' + 10 + 1) % 10 +
'0';
8072 ans[5][2] = (ans[5][2] -
'0' + 10 - 1) % 10 +
'0';
8073 ans[6][3] = (ans[6][3] -
'0' + 10 + 1) % 10 +
'0';
8074 ans[7][3] = (ans[7][3] -
'0' + 10 - 1) % 10 +
'0';
8077 queue<pair<int, string>> q;
8078 q.push({0,
"0000"});
8080 auto [step, code] = q.front();
8081 if(code == target) {
8086 if(deads.contains(code)) {
8089 auto nexts = get_nexts(code);
8090 for(
auto &next: nexts) {
8091 if(!vis.contains(next)) {
8093 if(next == target) {
8096 q.push({step + 1, next});
被这些函数引用 leetcode::open_the_lock::TEST().
该类的文档由以下文件生成: