题解 | #名字串生成II#
名字串生成II
https://www.nowcoder.com/practice/a90b0c33344e4b8488fe0b376de3205d
知识点:字符串
思路:和上一题思路一致,求最大公共串,只需要判断,是否是str1包含2,或者str2包含1即可
编程语言:java
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param str1 string字符串
* @param str2 string字符串
* @return string字符串
*/
public String lcmOfStrings (String str1, String str2) {
// write code here
if(str1.contains(str2))
return str1;
else if(str2.contains(str1))
return str2;
else
return "";
}
}

查看11道真题和解析