Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from typing import List


class Solution:
def average(self, salary: List[int]) -> float:
return (sum(salary) - max(salary) - min(salary)) / (len(salary) - 2)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Solution(object):
def countOdds(self, low, high):
"""
:type low: int
:type high: int
:rtype: int
"""
return (high + 1) / 2 - low / 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import List


class Solution:
def nearestValidPoint(self, x: int, y: int, points: List[List[int]]) -> int:
dist = -1
index = -1
for i, j in enumerate(points):
xi, yi = j
if x == xi or y == yi:
temp = abs(x - xi) + abs(y - yi)
if dist == -1 or temp < dist:
dist = temp
index = i
return index
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
s = set(s)
return len(s)
17 changes: 17 additions & 0 deletions Algorithms/python/ShortEncodingofWords/Short-Encoding-of-Words.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import collections
from functools import reduce
from typing import List


class Solution:
def minimumLengthEncoding(self, words: List[str]) -> int:
words = list(set(words)) # remove duplicates
Trie = lambda: collections.defaultdict(Trie)
trie = Trie()

nodes = [reduce(dict.__getitem__, word[::-1], trie)
for word in words]

return sum(len(word) + 1
for i, word in enumerate(words)
if len(nodes[i]) == 0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


class Solution:
def greatestLetter(self, s: str) -> str:
ans = []
for i in s:
if i.islower():
if i.upper() in s:
ans.append(i.upper())
if i.isupper():
if i.lower() in s:
ans.append(i.upper())
if len(ans):
return sorted(ans)[-1]
return ""

sol = Solution()
print(sol.greatestLetter("arRAzFif"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Solution:
def minimumNumbers(self, num: int, k: int) -> int:
def check(unit_digit, X):
for times in range(1, 11):
digit = (X * times) % 10
if (digit == unit_digit):
return times
return -1

unit_digit = num % 10
times = check(unit_digit, k)
if (times == -1):
return times
else:
if (num >= (times * k)):
return times
else:
return -1



sol = Solution()
x = sol.minimumNumbers(58, 9)
print(x)
140 changes: 67 additions & 73 deletions README.md

Large diffs are not rendered by default.