Skip to content

Commit 96c882c

Browse files
committed
finish one leetcode
1 parent 5ea1184 commit 96c882c

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

[beta]Merged String Checker.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def is_merge(s, part1, part2):
2+
part1 = list(part1)
3+
part2 = list(part2)
4+
for i in range(len(s)):
5+
if s[i] == part1[0]:
6+
print(part1)
7+
print(part1.pop())
8+
9+
10+
print(is_merge('codewars', 'cod', 'ewars'))
11+
print(is_merge('Bananas from Bahamas', 'Bahas', 'Bananas from am'))
12+
13+
#if s[i] in part1 and s[i] in part2:
14+
#if is_merge(''.join(s[i+1:]),part1.pop()[::-1],part2[::-1]):
15+
# return True
16+
#return False

[leetcode]Contains Duplicate.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
# @param {integer[]} nums
3+
# @return {boolean}
4+
def containsDuplicate(self, nums):
5+
res = None
6+
for n in sorted(nums):
7+
if n == res:
8+
return True
9+
else:
10+
res = n
11+
return False

[leetcode]Majority Element.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
# @param {integer[]} nums
3+
# @return {integer}
4+
def majorityElement(self, nums):
5+
sorted(nums)
6+
numDict = {}
7+
for n in nums:
8+
numDict[n] = numDict.get(n,0) + 1
9+
return max(numDict.values())
10+
11+
test = Solution()
12+
print(test.majorityElement([1,2,3,4,4,4,5,7,7,7,4,7]))

[leetcode]ZigZag Conversion.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
# @param {string} s
3+
# @param {integer} numRows
4+
# @return {string}
5+
def convert(self, s, numRows):
6+
contain = [[] for __ in range(numRows)]
7+
trans = tuple(range(numRows)) + tuple(range(numRows-1)[::-1])
8+
shift = (numRows - 1) * 2 if numRows > 1 else 1
9+
for i in range(len(s)):
10+
contain[trans[i%shift]].append(s[i])
11+
return ''.join([''.join(con) for con in contain])
12+
13+
test = Solution()
14+
print(test.convert("PAYPALISHIRING", 3))
15+
print(test.convert("ABCD", 1))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy