primeiro commit
This commit is contained in:
22
1786-merge_strings_alternately/python/1768.py
Normal file
22
1786-merge_strings_alternately/python/1768.py
Normal file
@ -0,0 +1,22 @@
|
||||
# 1768. Merge String Alternaly
|
||||
#
|
||||
# You are given two strings word1 and word2. Merge the strings by adding
|
||||
# letters in alternating order, starting with word1.
|
||||
# If a string is longer than the other, append the additional letters
|
||||
# onto the end of the merged string.
|
||||
#
|
||||
# Return the merged string.
|
||||
|
||||
def mergeStringsAlternately(word1: str, word2: str) -> str:
|
||||
merged_string: str = ""
|
||||
for i in range(max(len(word1), len(word2))):
|
||||
if (i >= len(word1)):
|
||||
merged_string += word2[i:]
|
||||
break
|
||||
elif (i >= len(word2)):
|
||||
merged_string += word1[i:]
|
||||
break
|
||||
else:
|
||||
merged_string += word1[i]
|
||||
merged_string += word2[i]
|
||||
return merged_string
|
||||
13
242-valid_anagram/python/242.py
Normal file
13
242-valid_anagram/python/242.py
Normal file
@ -0,0 +1,13 @@
|
||||
# 242. Valid Anagram
|
||||
#
|
||||
# https://leetcode.com/problems/valid-anagram/
|
||||
#
|
||||
# Given two strings s and t, return true if t is an anagram of s, and false otherwise.
|
||||
|
||||
def isAnagram(s: str, t: str) -> bool:
|
||||
if len(s) != len(t):
|
||||
return False
|
||||
for i in range(len(s)):
|
||||
if s.count(s[i]) != t.count(s[i]):
|
||||
return False
|
||||
return True
|
||||
@ -0,0 +1,11 @@
|
||||
# 28. Find the Index of the First Occurrence in a String
|
||||
# https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string
|
||||
#
|
||||
# Given two strings needle and haystack, return the index of the first
|
||||
# occurrence of needle in haystack, or -1 if needle is not part of haystack.
|
||||
|
||||
def findIndexOfFirstOccurrence(haystack: str, needle: str) -> int:
|
||||
index_first_occurrence: int = -1
|
||||
if (index_first_occurrence := haystack.find(needle)) >= 0:
|
||||
return index_first_occurrence
|
||||
return -1
|
||||
24
283-move_zeroes/python/283.py
Normal file
24
283-move_zeroes/python/283.py
Normal file
@ -0,0 +1,24 @@
|
||||
# 283. Move Zeroes
|
||||
# https://leetcode.com/problems/move-zeroes/
|
||||
#
|
||||
# Given an integer array nums, move all 0's to the end of it while maintaining
|
||||
# the relative order of the non-zero elements.
|
||||
#
|
||||
# Note that you must do this in-place without making a copy of the array.
|
||||
|
||||
# exemplo: dada a cadeia '00001' resultado final é '10000'
|
||||
|
||||
def moveZeroes(self, nums: list[int]) -> None:
|
||||
"""
|
||||
Do not return anything, modify nums in-place instead.
|
||||
"""
|
||||
for i in range(len(nums)):
|
||||
for j in range(i+1, len(nums)):
|
||||
if nums[j] != 0:
|
||||
nums[i] = nums[j]
|
||||
nums[j] = 0
|
||||
|
||||
if nums[i] == 0 and i < len(nums)-1:
|
||||
if nums[i+1] != 0:
|
||||
nums[i] = nums[i+1]
|
||||
nums[i+1] = 0
|
||||
14
389-find_the_difference/389.py
Normal file
14
389-find_the_difference/389.py
Normal file
@ -0,0 +1,14 @@
|
||||
# 389. Find the Difference
|
||||
# https://leetcode.com/problems/find-the-difference
|
||||
#
|
||||
# You are given two strings s and t.
|
||||
#
|
||||
# String t is generated by random shuffling string s and then add one more letter at a random position.
|
||||
#
|
||||
# Return the letter that was added to t.
|
||||
|
||||
def findTheDifference(s: str, t: str) -> str:
|
||||
for i in range(len(t)):
|
||||
if s.count(t[i]) != t.count(t[i]):
|
||||
return t[i]
|
||||
return ""
|
||||
10
459-repeated_substring_pattern/python/459.py
Normal file
10
459-repeated_substring_pattern/python/459.py
Normal file
@ -0,0 +1,10 @@
|
||||
# https://leetcode.com/problems/repeated-substring-pattern/
|
||||
#
|
||||
# 459. Repeated Substring Pattern
|
||||
#
|
||||
# Given a string s, check if it can be constructed by taking a substring of
|
||||
# it and appending multiple copies of the substring together.
|
||||
|
||||
def repeatedSubstringPattern(s: str) -> bool:
|
||||
result: bool = False
|
||||
return result
|
||||
Reference in New Issue
Block a user