Skip to content

Instantly share code, notes, and snippets.

View mohneesh7's full-sized avatar

Mohneesh S mohneesh7

  • Nuzvid
View GitHub Profile
@mohneesh7
mohneesh7 / Valid Palindrome.py
Created October 6, 2024 17:32
Solution for Valid Palindrome
# Solution for Valid Palindrome
class Solution:
def isPalindrome(self, s: str) -> bool:
s = s.lower()
s_list = list(s)
s = ''.join([x for x in s_list if x.isalnum()])
return s == s[::-1]
@mohneesh7
mohneesh7 / Two Sum II - Input Array Is Sorted.py
Created October 6, 2024 17:32
Solution for Two Sum II - Input Array Is Sorted
# Solution for Two Sum II - Input Array Is Sorted
class Solution:
def diff_bw_nums(self, a: int, b: int) -> int:
return a-b
def twoSum(self, numbers: List[int], target: int) -> List[int]:
left = 0
right = len(numbers) - 1
@mohneesh7
mohneesh7 / Squares of a Sorted Array.py
Created October 6, 2024 17:32
Solution for Squares of a Sorted Array
# Solution for Squares of a Sorted Array
class Solution:
def sortedSquares(self, nums: List[int]) -> List[int]:
left = 0
right = len(nums) - 1
result = []
while left <= right:
if (nums[left]**2) > (nums[right]**2):
@mohneesh7
mohneesh7 / Roman to Integer.py
Created October 6, 2024 17:32
Solution for Roman to Integer
# Solution for Roman to Integer
class Solution:
def romanToInt(self, s: str) -> int:
total = 0
num_dict = {
'I' : 1,
'V' : 5,
'X' : 10,
'L' : 50,
@mohneesh7
mohneesh7 / Reverse String.py
Created October 6, 2024 17:32
Solution for Reverse String
# Solution for Reverse String
class Solution:
def reverseString(self, s: List[str]) -> None:
"""
Do not return anything, modify s in-place instead.
"""
# case check for single element
# if len(s) <= 1:
# return
@mohneesh7
mohneesh7 / Merge Strings Alternately.py
Created October 6, 2024 17:32
Solution for Merge Strings Alternately
# Solution for Merge Strings Alternately
class Solution:
def mergeAlternately(self, word1: str, word2: str) -> str:
new_string = []
min_length = min(len(word1), len(word2))
if len(word1) != len(word2):
if len(word1) > len(word2):
temp_string = word1[min_length:]
else:
@mohneesh7
mohneesh7 / Is Subsequence.py
Created October 6, 2024 17:32
Solution for Is Subsequence
# Solution for Is Subsequence
class Solution:
def isSubsequence(self, s: str, t: str) -> bool:
if s == '':
return True
s_list = list(s)
for char in t:
if s_list != [] and char == s_list[0]:
@mohneesh7
mohneesh7 / Contains Duplicate.py
Created October 6, 2024 17:32
Solution for Contains Duplicate
# Solution for Contains Duplicate
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
# import numpy as np
# from collections import Counter
# counter = Counter(nums)
# for x in counter:
@mohneesh7
mohneesh7 / Jewels and Stones.py
Created October 6, 2024 16:31
Solution for Jewels and Stones
class Solution:
def numJewelsInStones(self, jewels: str, stones: str) -> int:
num_jewels = 0
for char in stones:
if char in jewels:
num_jewels += 1
return num_jewels
@mohneesh7
mohneesh7 / Find Closest Number to Zero.py
Created October 6, 2024 13:05
Solution for Find Closest Number to Zero
class Solution:
def diff_of_num(self, num):
if num <= 0:
return -num
else:
return num
def findClosestNumber(self, nums):
closest = nums[0]