Skip to content

Instantly share code, notes, and snippets.

View Robotboy93's full-sized avatar
🎯
Focusing

Shubham Robotboy93

🎯
Focusing
  • Oil India Limited
  • Duliajan, Assam
View GitHub Profile
@Robotboy93
Robotboy93 / gist:5ccdf2750c0a29b81ab3fb3c03f54516
Created September 18, 2022 12:12
A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers. Given a string s, return true if it is a palindrome, or false otherwise.
class Solution:
def isPalindrome(self, s: str) -> bool:
c = 0
z = [y.upper() for y in str(s) if y.isalnum()]
for i in range(len(z)//2):
if z[i] != z[len(z)-1-i]:
c = c+1
break
return(1-c)
pass
@Robotboy93
Robotboy93 / gist:5825f0eb48d1b1704543ab78f1395cc6
Created September 12, 2022 16:05
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.
class Solution:
def strStr(self, haystack: str, needle: str) -> int:
x = [a for a in haystack]
y = [b for b in needle]
k = -1
if len(y) <= len(x):
for i in range(len(x)-len(y)+1):
if x[i] == y[0]:
for j in range(len(y)):
if x[i+j] == y[j]:
@Robotboy93
Robotboy93 / gist:0791f69aec9369cb1ff36f1245ab919e
Created September 12, 2022 14:27
Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed. Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the first part of the array nums. More formally, if there are k elements after…
class Solution:
def removeElement(self, nums: List[int], val: int) -> int:
z = len(nums)
k = 0
while val in nums:
for i in range(len(nums)):
if nums[i] == val:
k = k+1
del nums[i]
@Robotboy93
Robotboy93 / gist:afd7341d43a3dff4056e242100fc7af3
Created September 11, 2022 12:11
Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any orde
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
a= b = 0
for i in range(len(nums)):
c = nums[i]
del nums[i]
if (target-c) in nums:
a = i
@Robotboy93
Robotboy93 / gist:a894a860ec5a46077c88b05f343fd118
Created September 11, 2022 12:02
Given an integer x, return true if x is palindrome integer. An integer is a palindrome when it reads the same backward as forward. For example, 121 is a palindrome while 123 is not.
class Solution:
def isPalindrome(self, x: int) -> bool:
c = 0
z = [y for y in str(x)]
for i in range(len(z)//2):
if z[i] != z[len(z)-1-i]:
c = c+1
break