Find the longest word given a collection

前端 未结 9 1591
既然无缘
既然无缘 2021-01-30 14:03

It is a google interview question and I find most answers online using HashMap or similar data structure. I am trying to find a solution using Trie if possible. Anybody could gi

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-30 14:56

    I tried to code this problem in C++ ..where i created my own hash key and go through all the combination with the given characters.

    Going through all the combination from these input characters from the largest length to 1

    Here is my solution

    #include "iostream"
    #include 
    
    using namespace std;
    
    int hash_f(string s){
            int key=0;
            for(unsigned int i=0;i0;i--)
                {
                    if( ((i==n-1)&&indexes[i] m) 
                        break;
                    for(int i=1;i0;i--){
            r = combination_m_n(str, str.size(),i ,num);
            for(int i=0;i

提交回复
热议问题