commit 0204a191c78e9e1ba369e7dc8680b7a817d1b87c Author: Luis Rodrigues Date: Wed Feb 12 12:33:39 2025 +0000 primeiro commit diff --git a/1786-merge_strings_alternately/python/1768.py b/1786-merge_strings_alternately/python/1768.py new file mode 100644 index 0000000..e3195d9 --- /dev/null +++ b/1786-merge_strings_alternately/python/1768.py @@ -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 diff --git a/242-valid_anagram/python/242.py b/242-valid_anagram/python/242.py new file mode 100644 index 0000000..89922db --- /dev/null +++ b/242-valid_anagram/python/242.py @@ -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 diff --git a/28-find_the_index_of_the_first_occurrence_in_a_string/python/28.py b/28-find_the_index_of_the_first_occurrence_in_a_string/python/28.py new file mode 100644 index 0000000..ef5aa0d --- /dev/null +++ b/28-find_the_index_of_the_first_occurrence_in_a_string/python/28.py @@ -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 diff --git a/283-move_zeroes/python/283.py b/283-move_zeroes/python/283.py new file mode 100644 index 0000000..c354e09 --- /dev/null +++ b/283-move_zeroes/python/283.py @@ -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 diff --git a/389-find_the_difference/389.py b/389-find_the_difference/389.py new file mode 100644 index 0000000..5361b79 --- /dev/null +++ b/389-find_the_difference/389.py @@ -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 "" diff --git a/459-repeated_substring_pattern/python/459.py b/459-repeated_substring_pattern/python/459.py new file mode 100644 index 0000000..367b66a --- /dev/null +++ b/459-repeated_substring_pattern/python/459.py @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..1b398de --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +https://leetcode.com/ +