Skip to content

Commit

Permalink
leetcode LCP , Programmers Brute_force
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrevile committed Jan 23, 2022
1 parent 229fd0c commit fddebb7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Programmers/메뉴 리뉴얼.py
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
19 changes: 19 additions & 0 deletions leetcode JS/14. Longest Common Prefix.js
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;
};

0 comments on commit fddebb7

Please sign in to comment.