uopspop

Untitled

Feb 4th, 2021
669
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2.     public boolean wordBreak(String s, List<String> wordDict) {
  3.        
  4.         return wordBreak_helper(s, wordDict, 0);
  5.        
  6.     }
  7.    
  8.     public boolean wordBreak_helper(String s, List<String> wordDict, int i_dict) {
  9.         if (i_dict == wordDict.size()) {
  10.             if (s.isEmpty()) return true;
  11.             return false;
  12.         }
  13.        
  14.         // use it
  15.         String word = wordDict.get(i_dict);
  16.         boolean result_use_it = wordBreak_helper(s.replaceAll(word,""), wordDict, i_dict + 1);
  17.         // not use it
  18.         boolean result_not_use_it = wordBreak_helper(s, wordDict, i_dict + 1);
  19.        
  20.         return result_use_it || result_not_use_it;
  21.        
  22.     }
  23. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×