Java repeated letter check in string

后端 未结 5 507
余生分开走
余生分开走 2021-01-27 12:43

I\'m having problem figuring out how to check from users input letters that were repeated. Program needs to output repeated letter as true and if there isn\'t any then as false.

5条回答
  •  有刺的猬
    2021-01-27 13:16

    1.) Sort the character array.

    2.) Iterate through the array to see if ith value == (i+1)th value. If any found, return false. Else, return true.

    Time complexity: O(nlogn) (for sorting)

    Space complexity: O(1)

提交回复
热议问题