Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一组字符串。如果一个字符串是另一个字符串的子字符串,那么前者应该被移除该集合。
我的想法是迭代原始集合中的所有字符串,并针对集合中的其他字符串对每个字符串进行测试,并删除原始集合中其他字符串的子字符串。但这会导致对原始集的就地修改,这可能会导致实现中的一些问题。
有没有人有更好的想法应该如何实施?谢谢。
你的问题不是很清楚。但如果我理解正确,你可以做这样的事情
l = sorted(["abcd", "abc", "ab", "a"], key = len) print [ss for idx, ss in enumerate(l) if all(ss not in cs for cs in l[idx + 1:])]
输出
['abcd']
I have class Menu, it's a self to self with manytoone and onetomany relational.
package models; import java.util.*; import javax.persistence.*; import play.