Quick actions

cmd+k|ctrl+k

Navigation

Languages

longestword

Snippet info

Language

Dart

Visibility

public

Author

obihenry578

Created

2025-03-09T23:17:38.479253Z

Updated

2025-03-09T23:17:38.479253Z

import 'dart:io';

void main() {
  

String LongestWord(String sen) {
  List<String> maxword = [];
  int maxsum = 0;
  List<String> currentword = [];
for(var i = 0; i < sen.length; i++){

  if(RegExp(r'[A-Za-z0-9]').hasMatch(sen[i] )){
    // currentsum += 1;
    currentword.add(sen[i]);

  }else{
    //   if (currentword.length > maxword.length) {
    //     maxword = List.from(currentword);
    //   }
      currentword.clear();
   
    
  }

      print(maxword);
            print(currentword);
  if(currentword.length > maxword.length ){
    maxword = List.from(currentword);
  }
  

}
print(maxword);
sen = maxword.join(' ');
print(sen);
  // code goes here  
  return sen;

}
   


print(LongestWord("I love dogs"));
}
INFO