leetcode127

BFS,然后利用set查找很快的特点

class Solution {
public:
    int ladderLength(string beginWord, string endWord, vector& wordList) {
        setdict;
        setvis;
        for(string s : wordList) dict.insert(s);
        if(!dict.count(endWord)) return 0;
        
        queueq;
        q.push(beginWord);
        vis.insert(beginWord);
        int cnt = 1;
        while(!q.empty())
        {
            int len = q.size();
            cnt++;
            for(int i = 0;i

 

你可能感兴趣的:(leetcode)