简体   繁体   English

给定两个字符串,检查它们是否等于k,每个长度为k的子字符串都出现在两个字符串上,并且必须为max

[英]Given two strings, check if they're k-equal, every substring of length k appear on both and has to be max

I'm trying to solve a problem: Given 2 strings, I need to check if they're k-equal, meaning every sub string of length k in str1 appears in str2 and vice versa. 我正在尝试解决一个问题:给定2个字符串,我需要检查它们是否等于k,这意味着str1中长度为k的每个子字符串都出现在str2中,反之亦然。 The number of occurnces of the sub-strings does not have to be equal though. 但是,子字符串的出现次数不必相等。 we can assume that the string are zero equal by default. 我们可以假设默认情况下字符串为零。 Lastly, the k has to be the highest number we can find. 最后,k必须是我们可以找到的最大数。 thus if there are sub-strings of length 1 and length 2 that appear on both strings, we should return just the strings with length 2. 因此,如果两个字符串上都出现了长度为1和长度为2的子字符串,我们应该只返回长度为2的字符串。

How can I approach this with Collections? 如何使用收藏夹解决这个问题? for example with HashMap. 例如使用HashMap。

Example: 例: 在此处输入图片说明

Hash all substring of str1 in a HashSet, lets say hash1. 将str1的所有子字符串哈希到一个HashSet中,比方说hash1。 Now generate substrings of str2 and check if it exists in hash1 and also maintain a max variable . 现在生成str2的子字符串,并检查它是否存在于hash1中,并还维护一个max变量。 I thinks this should work but its kind of bruteforce approach. 我认为这应该有效,但是它是一种蛮力的方法。

暂无
暂无

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

相关问题 从给定字符串中打印所有可能长度为 k 的字符串,并允许重复使用 usibg arraylist - print all the strings possible of length k from a given string with repition allowed usibg arraylist 查找数组中两个数字的总和是否等于 k - Find if sum of two numbers in an array is equal to k 给定一个由 N 个整数组成的数组 A,返回最大的整数 K>0,使得数组 A 中同时存在 K 和 -K(相反的数) - given an array A of N integers, return the largest integer K>0 such that both K and -K(the opposite number) exist in array A 每k步同步两个线程 - Syncronization of two threads every k steps JUnit断言两个字符串是否相等 - JUnit asserting two Strings whether they're equal or not 代码说明(打印所有可能的长度为 K 的字符串) - Explanation about the code (print all possible strings of length K) 递归方法,它接受输入s和k并生成长度为k的所有字符串 - Recursive method that takes an input s and k and generates all the strings of length k 给定两个字符串,确定它们是否共享一个共同的 substring - Given two strings, determine if they share a common substring 给定两个字符串,确定1是否是递归的另一个子字符串 - Given two Strings, determine if 1 is a substring of the other recursively 最长回文 substring 实现 - kj-1 如何获得回文 substring 的长度 - Longest palindromic substring implementation- how k-j-1 gets the length of the palindromic substring
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM