Explicación de Striver sobre la estructura de datos de prueba
class Node{ Node [] node = new Node[26]; boolean flag; public Node(){ } public boolean containsKey(char c){ return node[c-'a']!=null; } public void put(char c, Node n){ node[c-'a'] = n; } public Node get(char c){ return node[c-'a']; } public void setFlag() { this.flag = true; } public boolean getFlag(){ return this.flag; } } class Trie { Node root; public Trie() { root = new Node(); } //will take tc : O(len) of the word public void insert(String word) { Node node = root; for(int i =0;iTrie estructura de datos II
explicación del luchador para una mejor comprensión
import java.util.* ; import java.io.*; class Node { Node node[] = new Node[26]; int endWith = 0;// will keep track of no. of words ending with this word int countPrefix=0;// will keep track of no. of words starting with this word public Node(){ } public boolean containsKey(char c){ return node[c-'a']!=null; } public void put(char c, Node n){ node[c-'a'] = n; } public Node get(char c){ return node[c-'a']; } public void incrementCountPrefix() { this.countPrefix; } public void decrementCountPrefix(){ --this.countPrefix; } public void incrementEndWith(){ this.endWith; } public void deleteEndWith(){ --this.endWith; } public int getCountPrefix(){ return this.countPrefix; } public int getEndWith(){ return this.endWith; } } public class Trie { Node root; public Trie() { // Write your code here. root = new Node(); } public void insert(String word) { Node node = root; for(int i =0;iCadena completa
// tc : O(n*l) import java.util.* ; import java.io.*; class Node{ Node[] node = new Node[26]; boolean flag; public Node(){} public void put(char c , Node n){ node[c-'a'] = n; } public boolean containsKey(char c){ return node[c-'a']!=null; } public Node get(char c){ return node[c-'a']; } public void setEnd(){ this.flag = true; } public boolean isEnd(){ return this.flag; } } class Trie{ Node root; public Trie(){ root = new Node(); } public boolean checkIfPrefixPresent(String s){ Node node = root; boolean flag= true; for(int i = 0;iContar subcadena distinta
Tc: O(n^2) para insertar una subcadena única diferente en
Pruebe la estructura de datosimport java.util.ArrayList; public class Solution { Node root; static int count; public Solution(){ root = new Node(); } public static int countDistinctSubstrings(String s) { count = 0; // Write your code here. Solution sol = new Solution(); for(int i =0;i
Descargo de responsabilidad: Todos los recursos proporcionados provienen en parte de Internet. Si existe alguna infracción de sus derechos de autor u otros derechos e intereses, explique los motivos detallados y proporcione pruebas de los derechos de autor o derechos e intereses y luego envíelos al correo electrónico: [email protected]. Lo manejaremos por usted lo antes posible.
Copyright© 2022 湘ICP备2022001581号-3