题目:
给定一个字符串数组strs, 再给定两个字符串str1和str2,返回在strs中str1和str2的最小距离,如果str1和str2为null,或者不再strs中,都返回-1
列如:
strs = {"1","3","3","2","3","1","3"} ,str1 = "1" str2 = "2" 返回2
strs = {"CD"},str1 = "CD",str2="AC" 返回-1
代码实现:
package com.chenyu.string.cn;public class MinDistance {public static void main(String[] args) {String[] ss = {"a", "b", "c", "d", "c", "a", "d"};int result = minDistance(ss, "a", "d");System.out.println(result);}public static int minDistance(String[] target, String str1, String str2) {if (target == null || target.length == 0) {return -1;} if (str1 == nu