Leetcode with dani
前往频道在 Telegram
Join us and let's tackle leet code questions together: improve your problem-solving skills Preparing for coding interviews learning new algorithms and data structures connect with other coding enthusiasts
显示更多1 240
订阅者
-124 小时
-37 天
-1730 天
帖子存档
1 240
it's good. we did better from 78 % of submitted code in python by running time
20 5月 2024, 09:33
1 240
it good. we are better than 78% of submitted code in python by running time
20 5月 2024, 09:31
20 5月 2024, ~09:32
1 240
Let's tackle the question of finding the number that appears only once in a list.
We could iterate through the list, comparing each element to all others to count occurrences. This approach would work, but it has a time complexity of n^2, exceeding the given constraint of linear time (O(n)).
Since the question guarantees that all other elements appear twice, we can exploit this property. Here's how:
Convert the list to a set. Sets eliminate duplicates, leaving only the unique element.
Calculate the sum of the elements in the original list and the set.
Unique number = Sum of list elements - (2 * Sum of set elements)
This method efficiently finds the unique element in linear time.
There's an even better approach called the XOR method. If you'd like an explanation of how it works, I can provide the code and break it down for you
class Solution:
def singleNumber(self, nums: List[int]) -> int:
result = 0
for i in nums:
result^=i
return result20 5月 2024, 09:30
20 5月 2024, ~09:59
1 240
let's do the question the question above that asks two find the number which appears only once , so we can compare each element vs the list it self and try to count it and we can return the number that only appers once but the question restricts us to find in linear time but in the code is n^2 time complexity so we can use it ,so let's find another method so the question says the list contain one unique element and the others are exits twice so by this logic. we create empty list and copy the list to set then we will find the sum of the list and the set then the unique number = total element in the list - (2*total element in the set).so we can do the question by this method but there is also another method that is better than the prevouies it is XOR method i just write the code if u want explanation i will send it but first try to figure it out ur self how it works
class Solution:
def singleNumber(self, nums: List[int]) -> int:
result = 0
for i in nums:
result^=i
return result class Solution:
def singleNumber(self, nums: List[int]) -> int:
result = 0
for i in nums:
result^=i
return result20 5月 2024, 09:26
20 5月 2024, ~09:26
1 240
Repost from Leetcode with dani
#leet_code_Q1 #Array Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
You must implement a solution with a linear runtime complexity and use only constant extra space.
Example 1:
Input: nums = [2,2,1]
Output: 1
Example 2:
Input: nums = [4,1,2,1,2]
Output: 4
Example 3:
Input: nums = [1]
Output: 1 Each element in the array appears twice except for one element which appears only once.
20 5月 2024, 08:31
20 5月 2024, ~08:31
1 240
ኖትኮይን ሳትሰሩ ያለፋቹህ ሰዎች ሌላ ተመሳሳይ airdrop ስለመጣ ጊዜው ሳያልፍ ጀምሩ👇
https://t.me/tapswap_mirror_1_bot?start=r_659354356
🎁 +2.5k Shares as a first-time gift
use vpn to get 600000 coin
20 5月 2024, 07:40
30 5月 2024, ~04:00
1 240
ኖትኮይን ሳትሰሩ ያለፋቹህ ሰዎች ሌላ ተመሳሳይ airdrop ስለመጣ ጊዜው ሳያልፍ ጀምሩ👇
https://t.me/tapswap_mirror_2_bot?start=r_1379272048
🎁 +2.5k Shares as a first-time gift
use vpn to get 600000 coin
20 5月 2024, 06:01
30 5月 2024, ~04:00
1 240
#leet_code_Q1 #Array Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
You must implement a solution with a linear runtime complexity and use only constant extra space.
Example 1:
Input: nums = [2,2,1]
Output: 1
Example 2:
Input: nums = [4,1,2,1,2]
Output: 4
Example 3:
Input: nums = [1]
Output: 1 Each element in the array appears twice except for one element which appears only once.
20 5月 2024, 03:29
1 240
ኖትኮይን ሳትሰሩ ያለፋቹህ ሰዎች ሌላ ተመሳሳይ airdrop ስለመጣ ጊዜው ሳያልፍ ጀምሩ👇
https://t.me/mnemonic_game_bot/start?startapp=ref_5141207051
20 5月 2024, 02:45
30 5月 2024, ~04:00
1 240
Hey everyone,
Big news! This channel is evolving to focus on cracking LeetCode problems and sharpening your coding skills.
While I appreciate your interest in Python, I'm excited to embark on this new journey with you all, tackling LeetCode challenges together.
Why LeetCode?
Boost your coding interview skills: LeetCode problems are widely used by top tech companies, and mastering them will put you ahead of the curve.
Test and improve your problem-solving abilities: LeetCode offers a variety of problems ranging from easy to challenging, ensuring there's something for everyone.
Learn from each other: We can discuss solutions, share different approaches, and help each other overcome obstacles.
Get ready to:
Dive into LeetCode problems (all levels): We'll tackle a variety of challenges, from basic algorithms to more complex data structures.
Collaborate and discuss solutions: Share your thought processes, learn from different approaches, and help each other conquer the problems.
Become a LeetCode master: Together, we'll push ourselves and improve our coding skills to new heights.
Are you ready to join the LeetCode challenge?
Let's make this channel a hub for collaboration and LeetCode problem-solving!
P.S. Feel free to suggest specific LeetCode problems you'd like to tackle in the comments below.
Let's code together! let me know your ideas in the comment section and there is another group i created only for python i will post it below.
19 5月 2024, 14:09
1 240
ኖትኮይን ሳትሰሩ ያለፋቹህ ሰዎች ሌላ ተመሳሳይ airdrop ስለመጣ ጊዜው ሳያልፍ ጀምሩ👇
https://t.me/tapswap_mirror_2_bot?start=r_1379272048
🎁 +2.5k Shares as a first-time gift
19 5月 2024, 06:47
30 5月 2024, ~04:00
