Skip to content

Commit

Permalink
Programmers set,intersection union, leetcode splice
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrevile committed Jan 30, 2022
1 parent e3bce13 commit 17bd7bb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Programmers/[1차] 뉴스 클러스터링.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import re


def solution(str1, str2):
answer = 0
str1 = str1.upper()
str2 = str2.upper()
str1_list = []
str2_list = []

for i in range(len(str1) - 1):
temp = str1[i:i + 2]
if temp.isalpha() == True:
str1_list.append(temp)

for i in range(len(str2) - 1):
temp = str2[i:i + 2]
if temp.isalpha() == True:
str2_list.append(temp)

intersection = set(str1_list) & set(str2_list)
union = set(str1_list) | set(str2_list)

top = 0
bot = 0
for key in intersection:
top += min(str1_list.count(key), str2_list.count(key))
for key in union:
bot += max(str1_list.count(key), str2_list.count(key))

if bot == 0:
answer = 1
else:
answer = top / bot
answer = int(answer * 65536)
return answer
15 changes: 15 additions & 0 deletions leetcode JS/26. Remove Duplicates from Sorted Array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @param {number[]} nums
* @return {number}
*/
var removeDuplicates = function (nums) {
let i = 0;
while (i < nums.length - 1) {
j = i + 1;
if (nums[i] === nums[j]) {
nums.splice(j, 1);
} else {
i++;
}
}
};

0 comments on commit 17bd7bb

Please sign in to comment.