(Java) Leetcode 127. Word ladder--Word Solitaire

Source: Internet
Author: User

Given words (beginword and Endword), and a dictionary ' s word list, find the length of shortest trans Formation sequence from Beginword to Endword, such that:

    1. Only one letter can is changed at a time.
    2. Each transformed word must exist in the word list. Note that Beginword was not a transformed word.

Note:

    • Return 0 If there is no such transformation sequence.
    • All words has the same length.
    • All words contain only lowercase alphabetic characters.
    • Assume no duplicates in the word list.
    • Assume Beginword and Endword are non-empty and is not the same.

Example 1:

Input:beginword = "hit", Endword = "Cog", wordList = [' hot ', ' dot ', ' dog ', ' lot ', ' log ', ' cog ']output:5explanation:as one Shortest transformation is ' hit ', "Hot", "dot", "dog" and "cog", return its length 5.

Example 2:

Input:beginword = "hit" Endword = "cog" wordList = [' hot ', ' dot ', ' dog ', ' lot ', ' log ']output:0explanation:the Endword ' cog ' I s not in wordList, therefore no possible transformation.

Ah

(Java) Leetcode 127. Word ladder--Word Solitaire

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.