finding all distinct substring of a string

前端 未结 6 1714
借酒劲吻你
借酒劲吻你 2021-01-14 21:41

hello guys i was given homework problem where it asks me to find all distinct substring of a string. I have implemented a method which will tell you all the substrings of s

6条回答
  •  滥情空心
    2021-01-14 21:52

    Insert any new sub string into an array and check if it is already available available there don't add it to the array else do. When done loop through the array and print out the distinct sub strings.

    To check if an element exists in an array create a function that takes an array and a value as parameters. It would loop through the array looking for the value if found return true. Out of the loop return false.

    e.g.

    public static boolean(String target, String[] arr)
    {
      for(int i = 0; i < arr.length; i++){
          if(arr[i].equals(target))
             return true;
      }
       return false;
    }
    

提交回复
热议问题