Easy&Fast Solution, without Map


  • 0
    P

    '''
    public class Solution {
    public String[] findRestaurant(String[] list1, String[] list2) {
    List<String> result = new ArrayList<String>();
    boolean flag = false;
    for (int i = 0; i < list1.length+list2.length-1; i++) {
    for (int j = 0; j < list1.length && j <= i; j++) {
    if (i-j<list2.length && list1[j].equals(list2[i-j])) {
    result.add(list1[j]);
    flag = true;
    }
    }
    if (flag == true) {
    break;
    }
    }
    return (String[])result.toArray(new String[result.size()]);
    }
    }
    ''''


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.