-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
leetcode LCP , Programmers Brute_force
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from itertools import combinations | ||
def solution(orders, course): | ||
answer = [] | ||
|
||
for num in course: #코스 숫자 | ||
comb = {} | ||
for i in range(len(orders)): #주문 목록 | ||
if len(orders[i]) < num: #지금 주문이 조합수보다 작다면 넘기기 | ||
continue | ||
temp = list(combinations(list(orders[i]),num)) | ||
for key in temp: #현재 주문 조합 목록중에 | ||
menu = list(key) | ||
menu.sort() | ||
menu = "".join(menu) | ||
if menu not in comb: #현재 주문 조합이 없으면 추가 | ||
comb[menu] = 1 | ||
else: #있으면 1 증가 | ||
comb[menu] += 1 | ||
|
||
value_list = list(comb.values()) | ||
max_value = 0 | ||
|
||
if len(value_list) != 0: | ||
max_value = max(value_list) | ||
|
||
for key,val in comb.items(): #comb에서 | ||
if val == max_value and val >= 2: | ||
answer.append(key) | ||
|
||
answer.sort() | ||
|
||
|
||
return answer |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @param {string[]} strs | ||
* @return {string} | ||
*/ | ||
var longestCommonPrefix = function (strs) { | ||
if (strs.length === 0) { | ||
return ""; | ||
} | ||
let prefix = strs[0]; | ||
for (let i = 1; i < strs.length; i++) { | ||
while (strs[i].indexOf(prefix) !== 0) { | ||
prefix = prefix.substring(0, prefix.length - 1); | ||
if (prefix.length === 0) { | ||
return ""; | ||
} | ||
} | ||
} | ||
return prefix; | ||
}; |