Skip to content

Commit

Permalink
🎁 Added leetcode problems
Browse files Browse the repository at this point in the history
  • Loading branch information
crypticsy committed Jan 29, 2024
1 parent 3bde473 commit f97d0f9
Show file tree
Hide file tree
Showing 28 changed files with 90 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.DS_Store
*.py
.DS_Store
File renamed without changes.
File renamed without changes
34 changes: 34 additions & 0 deletions LeetCode 75/1071 Greatest Common Divisor of Strings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 1071. Greatest Common Divisor of Strings
# For two strings s and t, we say "t divides s" if and only if s = t + ... + t (i.e., t is concatenated with itself one or more times).

# Given two strings str1 and str2, return the largest string x such that x divides both str1 and str2.

# Example 1:

# Input: str1 = "ABCABC", str2 = "ABC"
# Output: "ABC"
# Example 2:

# Input: str1 = "ABABAB", str2 = "ABAB"
# Output: "AB"
# Example 3:

# Input: str1 = "LEET", str2 = "CODE"
# Output: ""


# Constraints:

# 1 <= str1.length, str2.length <= 1000
# str1 and str2 consist of English uppercase letters.

from math import gcd

class Solution:
def gcdOfStrings(self, str1: str, str2: str) -> str:
# base case that checks if keeping the strings create the same pattern
if str1 + str2 != str2 + str1:
return ""

gcd_length = gcd(len(str1), len(str2))
return str1[:gcd_length]
50 changes: 50 additions & 0 deletions LeetCode 75/1768 Merge Strings Alternately.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 1768. Merge Strings Alternately
# 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.

# Example 1:

# Input: word1 = "abc", word2 = "pqr"
# Output: "apbqcr"
# Explanation: The merged string will be merged as so:
# word1: a b c
# word2: p q r
# merged: a p b q c r
# Example 2:

# Input: word1 = "ab", word2 = "pqrs"
# Output: "apbqrs"
# Explanation: Notice that as word2 is longer, "rs" is appended to the end.
# word1: a b
# word2: p q r s
# merged: a p b q r s
# Example 3:

# Input: word1 = "abcd", word2 = "pq"
# Output: "apbqcd"
# Explanation: Notice that as word1 is longer, "cd" is appended to the end.
# word1: a b c d
# word2: p q
# merged: a p b q c d


# Constraints:

# 1 <= word1.length, word2.length <= 100
# word1 and word2 consist of lowercase English letters.


class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
output = ""

count = 0
while len(word1) > count and len(word2) > count:
output += word1[count] + word2[count]
count += 1

output += word1[count:]
output += word2[count:]

return output
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Inspired by this remarkable research, I'm embarking on a thrilling quest to mast

<br/>

Series 1 : [66 Days of Data Science](./66_Days_of_Data_Science/)
Series 1 : [66 Days of Data Science](./66%20Days%20of%20Data%20Science/)

Series 2 : [LeetCode 75](./LeetCode%2075/)

<br/>

Expand Down
4 changes: 2 additions & 2 deletions auto_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
TODAY=$(date +"%a,%d %b, %Y %I:%M %p")

# add all changes
git add *
git add .
# commit changes
git commit -m "66 Days of DS : Updated learning log till $TODAY"
git commit -m "🤖 Updated learning log till $TODAY with leetcode"
git push origin master

0 comments on commit f97d0f9

Please sign in to comment.