Find all possible substring in fastest way [duplicate]
问题 This question already has answers here : Generate all unique substrings for given string (14 answers) Closed 2 years ago . For String A = "abcd" then answer should be {a,ab,abc,abcd,b,bc,bcd,c,cd,d} To find all the substring I have used following method for (int i = 0; i < A.length(); i++) { for (int j = i+1; j <= A.length(); j++) { System.out.println(A.substring(i,j)); } } But according to my understanding the complexity goes to O(N^2) . Can we make it faster? I referred previous question