简体   繁体   English

Java方法在不特定于字母序列的字符串中查找字母集?

[英]Java method to find set of letters in a String not specific with sequence of Letters?

In Java I am developing scramble game for playing with words. 在Java中,我正在开发用于玩单词的争夺游戏。

If player1 sends letters like "B,A,C,N,R,E" , then again player1 should not send same set of letters ( sequence does not matter ) eg "A,B,C,N,R,E", "B,A,N,C,E,R" etc. 如果player1发送的字母类似“ B,A,C,N,R,E” ,那么player1不应再次发送同一组字母(顺序无关紧要),例如“ A,B,C,N,R,E”, “ B,A,N,C,E,R”

Is there anyway to find the given set of letters in a string not specific with sequence of Letters? 无论如何,在不是特定于字母序列的字符串中找到给定的字母集吗?

Corresponding to player1, you can sort and store the sequence he has sent. 对应于player1,您可以对他发送的序列进行排序和存储。 Next time he chooses a sequence, sort it and do a check in the map 下次他选择一个序列时,对其进行排序并在地图中进行检查

1) Sort the letters as it was said before. 1)按照之前所说的对字母进行排序。 Complexity O(n log n). 复杂度O(n log n)。

2) To implement some kind of array with counters where the ordinal number of the simbol in alphabet will be an index in mask array. 2)用计数器实现某种数组,其中simbol的序数将是掩码数组中的索引。 And use this mask array to match the words. 并使用此掩码数组来匹配单词。 Just like that Integer[] maskArray = [0(for A),0(for B),0(for C),etc.] Complexity O(n). 就像Integer [] maskArray = [0(对于A),0(对于B),0(对于C)等)复杂度O(n)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM