题解 | #名字串生成II#
名字串生成II
https://www.nowcoder.com/practice/a90b0c33344e4b8488fe0b376de3205d
考察字符串的应用。和上一道题目类似,直接判断两个字符串是否相互包含。
完整代码如下所示
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 "";
}
}
}