Created
July 1, 2019 08:02
-
-
Save restart916/2f6beef7107aab38ba44fc11dc44c02f to your computer and use it in GitHub Desktop.
20190630_leetcode_599_MinimumIndexSumofTwoLists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string[]} list1 | |
* @param {string[]} list2 | |
* @return {string[]} | |
*/ | |
var findRestaurant = function(list1, list2) { | |
let findListIndex = 2000 | |
let result = [] | |
for (let first in list1) { | |
first = parseInt(first) | |
let firstItem = list1[first] | |
let second = list2.indexOf(firstItem) | |
console.log(firstItem, second, findListIndex) | |
if (second > -1) { | |
if (first + second < findListIndex) { | |
findListIndex = first + second | |
result = [firstItem] | |
} else if (first + second == findListIndex) { | |
result.push(firstItem) | |
} | |
} | |
} | |
return result | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
일단 bf 로 다 풀어보았습니다. 원래 저기 list2.indexOf(firstItem) 대신에 findListIndex 변수써서 최대 findListIndex 만큼만 while 돌게 하면
그나마.. 덜 돌지 않을까 정도 생각했습니다.