9. Palindrom number #leet_code_Q4 #math #my_twopointer Given an integer x, return true if x is a
palindrome, and false otherwise.
Example 1:
Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.
Example 2:
Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example 3:
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
palindrome, and false otherwise.
Example 1:
Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.
Example 2:
Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example 3:
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Leetcode with dani
9. Palindrom number #leet_code_Q4 #math #my_twopointer Given an integer x, return true if x is a palindrome, and false otherwise. Example 1: Input: x = 121 Output: true Explanation: 121 reads as 121 from left to right and from right to left. Example 2:…
LeetCode
Palindrome Number - LeetCode
Can you solve this real interview question? Palindrome Number - Given an integer x, return true if x is a palindrome, and false otherwise.
Example 1:
Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.…
Example 1:
Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.…
Leetcode with dani
Palindrome number
share ur ides on the comment section
if you are interested to learn python join this group Python
Telegram
Python
Dani invites you to join this group on Telegram.
Leetcode with dani
9. Palindrom number #leet_code_Q4 #math #my_twopointer Given an integer x, return true if x is a palindrome, and false otherwise. Example 1: Input: x = 121 Output: true Explanation: 121 reads as 121 from left to right and from right to left. Example 2:…
answers which are sent From u:
Forwarded from Gizeale Wondie
left = 0
x = str(x)
right = len(x)-1
while left<= right:
if x[left]!= x[right]:
return False
left+=1
right-=1
return True
x = str(x)
right = len(x)-1
while left<= right:
if x[left]!= x[right]:
return False
left+=1
right-=1
return True
ምስጉን ነው በክፉዎች ምክር ያልሄደ፥ በኃጢአተኞችም መንገድ ያልቆመ፥ በዋዘኞችም ወንበር ያልተቀመጠ።
ነገር ግን በእግዚአ·በሔር ሕግ ደስ ይለዋል፥ ሕጉንም በቀንና በሌሊት ያስባል፡፡
እርሱም በውኃ ፈሳሾች ዳር እንደ ተተከለች፡ ፍሬዋን በየጊዜዋ እንደምትሰጥ፡ ቅጠልዋም እንደማይረግፍ ዛፍ ይሆናል፤ የሚሠራውም ሁሉ ይከናወንለታል።
ክፉዎች እንዲህ አይደሉም፡ ነገር ግን ነፋስ ጠርጎ እንደሚወስደው ትቢያ ናቸው... ስለዚህ ክፉዎች በፍርድ፥ ኃጢአተኞችም በጻድቃን ማኅበር አይቆሙም።
እግዚአብሔር የጻድቃንን መንገድ ያውቃልና፥ የክፉዎች መንገድ ግን ትጠፋለች።
❤9
I strongly recommend starting to do LeetCode questions as early as possible. Whether you use it in real life or not, many companies ask for this skill during technical interviews, and it's not likely to change anytime soon. So, do as many problems as you can. Thanks!
👍4💯2
Leetcode with dani pinned «I strongly recommend starting to do LeetCode questions as early as possible. Whether you use it in real life or not, many companies ask for this skill during technical interviews, and it's not likely to change anytime soon. So, do as many problems as you can.…»
This media is not supported in your browser
VIEW IN TELEGRAM
Binary Search Algorithm in 100 Seconds
👍3
704. Binary Search #Easy #leet_code_Q5 #binary_search Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1.
You must write an algorithm with O(log n) runtime complexity.
Example 1:
Input: nums = [-1,0,3,5,9,12], target = 9
Output: 4
Explanation: 9 exists in nums and its index is 4
Example 2:
Input: nums = [-1,0,3,5,9,12], target = 2
Output: -1
Explanation: 2 does not exist in nums so return -1
You must write an algorithm with O(log n) runtime complexity.
Example 1:
Input: nums = [-1,0,3,5,9,12], target = 9
Output: 4
Explanation: 9 exists in nums and its index is 4
Example 2:
Input: nums = [-1,0,3,5,9,12], target = 2
Output: -1
Explanation: 2 does not exist in nums so return -1
👍5
Leetcode with dani
704. Binary Search #Easy #leet_code_Q5 #binary_search Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You…
share ur solution on the comment section or in the group.
👍4
Leetcode with dani
704. Binary Search #Easy #leet_code_Q5 #binary_search Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You…
``` class Solution:
def search(self, nums: List[int], target: int) -> int:
left = 0
right = len(nums)-1
while(left<=right):
mid = (left+right)//2
if nums[mid] == target:
return mid
elif nums[mid] >target:
right = mid -1
else:
left = mid+1
return -1 ```
def search(self, nums: List[int], target: int) -> int:
left = 0
right = len(nums)-1
while(left<=right):
mid = (left+right)//2
if nums[mid] == target:
return mid
elif nums[mid] >target:
right = mid -1
else:
left = mid+1
return -1
👍5