# Longest Word in Dictionary through Deleting

Given a string and a string dictionary, find the longest string in the dictionary that can be formed by deleting some characters of the given string. If there are more than one possible results, return the longest word with the smallest lexicographical order. If there is no possible result, return the empty string.

**Example 1:**

```
Input:

s = "abpcplea", d = ["ale","apple","monkey","plea"]


Output:

"apple"
```

**Example 2:**

```
Input:

s = "abpcplea", d = ["a","b","c"]


Output:

"a"
```

分析

就是loo字典里每个word，然后每个word和s比较，2个指针一个在word 一个在s 同时出发

这里不用map 因为会乱序，本体要求Order

```
class Solution:
    def findLongestWord(self, s: str, d: List[str]) -> str:
        ll = len(s)
        maxLen,res = 0,''
        for p in d:
            ps=pp=0
            lp = len(p)
            while ps < ll and pp < lp:
                if p[pp] == s[ps]:
                    pp += 1
                ps += 1
            if pp == lp:
                if maxLen < lp:
                    maxLen = lp
                    res = p
                elif maxLen == lp:
                    if res > p:
                        res = p               
        return res
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nataliekung.gitbook.io/ladder_code/qiang-hua-4-shuang-zhi-zhen-ff09/longest-word-in-dictionary-through-deleting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
