Are you over 18 and want to see adult content?
More Annotations
![CoinExplorer.sk | Objavte svet Bitcoinu](https://www.archivebay.com/archive/d913af6e-7645-44c9-bfa0-bfe223258857.png)
CoinExplorer.sk | Objavte svet Bitcoinu
Are you over 18 and want to see adult content?
![Literatur- und Leseförderinitiative Wiener Bücherschmaus › Wiener Bücherschmaus](https://www.archivebay.com/archive/212ec787-80d6-45e9-963b-710e6a9c97f3.png)
Literatur- und Leseförderinitiative Wiener Bücherschmaus › Wiener Bücherschmaus
Are you over 18 and want to see adult content?
![DigiByte Global Blockchain | DigiByte - DigiByte Global Blockchain](https://www.archivebay.com/archive/0b33b416-33e4-4a13-8772-5d90f56be2c8.png)
DigiByte Global Blockchain | DigiByte - DigiByte Global Blockchain
Are you over 18 and want to see adult content?
![decade thirty | sketching | books | stationery | food](https://www.archivebay.com/archive/e2edabf4-8c29-45d3-9878-41df9be0dc7d.png)
decade thirty | sketching | books | stationery | food
Are you over 18 and want to see adult content?
![A complete backup of mrsgomezspanish.weebly.com](https://www.archivebay.com/archive/acf1e21a-8539-4625-9f6e-a12f3a96d437.png)
A complete backup of mrsgomezspanish.weebly.com
Are you over 18 and want to see adult content?
Favourite Annotations
![A complete backup of https://purethemes.net](https://www.archivebay.com/archive6/images/e964831c-bc1f-4fc6-a22f-de4e860810ba.png)
A complete backup of https://purethemes.net
Are you over 18 and want to see adult content?
![A complete backup of https://experian.es](https://www.archivebay.com/archive6/images/9a181415-3aa0-40e3-a426-3fadb16c28e4.png)
A complete backup of https://experian.es
Are you over 18 and want to see adult content?
![A complete backup of https://astig.ph](https://www.archivebay.com/archive6/images/6845d292-6c3b-45b0-86e7-d224e364befc.png)
A complete backup of https://astig.ph
Are you over 18 and want to see adult content?
![A complete backup of https://fcmitos.ru](https://www.archivebay.com/archive6/images/987f518d-9a46-4a50-9792-3dfbb4ab12af.png)
A complete backup of https://fcmitos.ru
Are you over 18 and want to see adult content?
![A complete backup of https://brennerchildrens.org](https://www.archivebay.com/archive6/images/5c64654f-1b6a-496c-aba1-d8a04d8e5871.png)
A complete backup of https://brennerchildrens.org
Are you over 18 and want to see adult content?
![A complete backup of https://askopinion.com](https://www.archivebay.com/archive6/images/9504fe44-badf-4604-98e0-4d0b6bdde4d4.png)
A complete backup of https://askopinion.com
Are you over 18 and want to see adult content?
![A complete backup of https://worldworcester.org](https://www.archivebay.com/archive6/images/fb084b89-f34c-4a94-9aa3-52ccaea67697.png)
A complete backup of https://worldworcester.org
Are you over 18 and want to see adult content?
![A complete backup of https://12348.com.cn](https://www.archivebay.com/archive6/images/71194322-3796-4a87-9d01-cd4132dcd8bb.png)
A complete backup of https://12348.com.cn
Are you over 18 and want to see adult content?
![A complete backup of https://policylab.us](https://www.archivebay.com/archive6/images/def711c3-7ad6-4fdb-81b6-e33697ed10d2.png)
A complete backup of https://policylab.us
Are you over 18 and want to see adult content?
![A complete backup of https://scriptium.nl](https://www.archivebay.com/archive6/images/d684546e-2a3c-44bc-b86f-59b04aeef656.png)
A complete backup of https://scriptium.nl
Are you over 18 and want to see adult content?
![A complete backup of https://speedpost.com.sg](https://www.archivebay.com/archive6/images/ba150d5e-ac76-42cc-85ee-151e53f217b8.png)
A complete backup of https://speedpost.com.sg
Are you over 18 and want to see adult content?
Text
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?Example 1:
Input:
Output: 1
Example 2:
Input:
Output: 4
Solution :
class Solution {
public:
int singleNumber(vector& nums) { // Sort the numbers std::sort(nums.begin(),nums.end()); for(unsigned int i=0;i{
if( i+1 < nums.size() ){
if(nums != nums)
{
return nums;
}
}
else
{
return nums;
}
}
return 0;
}
};
Mathematical solutionclass Solution {
public:
int singleNumber(vector& nums) { unsigned int result=0;// Get all unique number and add them std::set mSet (nums.begin(),nums.end()); for(std::set::iterator it=mSet.begin();it !=
mSet.end();it++)
{
result += *it;}
// we must have pairs , so double it result = 2* result;
// Reduce all the number to find what's left that must be
the
// un-matched number for(unsigned int i=0;i{
result -= nums;}
return result;
}
};
Posted by Mihir
at 1:33 AM
Reactions:
No comments:
Links to this post
Email This
BlogThis!
Share
to Twitter
Share
to Facebook
Share
to Pinterest
LEETCODE: CONTAINS DUPLICATE (C++) Given an array of integers, find if the array contains anyduplicates.
Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.Example 1:
Input:
Output: true
Example 2:
Input:
Output: false
Example 3:
Input:
Output: true
Solution1: brute force that works but exceeds time limits due to complexity of 0(n^2) bool containsDuplicate(vector& nums) { for(unsigned int i = 0 ; i< nums.size() ;i++){
for(unsigned int j = i+1 ; j< nums.size() ;j++){
if( nums == nums ) { return true; }}
}
return false;}
Solution 2: Complexity is reduced (Accepted Answer) bool containsDuplicate(vector& nums) {// Prevent against bad input if(nums.size() ==0)
{
return false;}
// Put the data in set std::set mSet (nums.begin(),nums.end());
// Sets are unique, and thus if the size is // same as vector then there are no duplicates if(mSet.size()==nums.size())
{
return false;}
else
{
return true;}
}
Posted by Mihir
at 12:52 AM
Reactions:
No comments:
Links to this post
Email This
BlogThis!
Share
to Twitter
Share
to Facebook
Share
to Pinterest
LEETCODE : SOLUTION ROTATE ARRAY (C++) Given an array, rotate the array to the right by _k_ steps, where _k_ is non-negative.Example 1:
Input: and _k_ = 3Output:
Explanation:
rotate 1 steps to the right: rotate 2 steps to the right: rotate 3 steps to the right:Example 2:
Input: and _k_ = 2Output:
Explanation:
rotate 1 steps to the right: rotate 2 steps to the right:Note:
* Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem. * Could you do it in-place with O(1) extra space?class Solution {
public:
void rotate(vector& nums, int k) {for(unsigned int i=0; i { nums.emplace(nums.begin(), nums); nums.pop_back();
}
}
};
Posted by Mihir
at 12:38 AM
Reactions:
No comments:
Links to this post
Email This
BlogThis!
Share
to Twitter
Share
to Facebook
Share
to Pinterest
Older Posts
Home
Subscribe to: Posts (Atom)SEARCH THIS BLOG
BLOG ARCHIVE
* ▼ 2020 (9)
* ▼ April (5)
* LeetCode : Single Number (C++) * LeetCode: Contains Duplicate (c++) * LeetCode : Solution Rotate Array (C++) * LeetCode : Solution Best Time to Buy and Sell Stoc... * debian how to open a folder in same gui * ► February (2) * ► January (2)* ► 2019 (4)
* ► September (1)* ► August (3)
* ► 2018 (1)
* ► January (1)* ► 2017 (8)
* ► July (5)
* ► June (2)
* ► April (1)
* ► 2016 (9)
* ► July (4)
* ► May (2)
* ► April (2)
* ► March (1)
* ► 2015 (8)
* ► July (2)
* ► February (6)* ► 2014 (3)
* ► May (1)
* ► March (1)
* ► February (1)* ► 2013 (15)
* ► December (1)* ► July (6)
* ► May (4)
* ► April (2)
* ► January (2)* ► 2012 (37)
* ► December (1) * ► November (12) * ► October (2) * ► September (1)* ► August (3)
* ► July (5)
* ► June (2)
* ► May (1)
* ► April (1)
* ► March (4)
* ► February (2) * ► January (3)* ► 2011 (57)
* ► December (3) * ► November (2) * ► October (12) * ► September (6)* ► August (1)
* ► July (2)
* ► June (10)
* ► May (6)
* ► April (5)
* ► March (3)
* ► February (5) * ► January (2)* ► 2010 (30)
* ► December (2) * ► November (4) * ► October (1) * ► September (2)* ► August (5)
* ► July (1)
* ► May (2)
* ► April (1)
* ► March (1)
* ► February (6) * ► January (5)* ► 2009 (81)
* ► December (3) * ► November (6) * ► October (1) * ► September (3)* ► August (1)
* ► July (17)
* ► June (8)
* ► May (9)
* ► April (11)
* ► March (4)
* ► February (11) * ► January (7)* ► 2008 (110)
* ► December (6) * ► November (2) * ► October (2) * ► September (1)* ► August (6)
* ► July (1)
* ► June (20)
* ► May (9)
* ► April (8)
* ► March (22)
* ► February (20) * ► January (13)* ► 2007 (47)
* ► December (8) * ► November (13) * ► October (22) * ► September (4)FOLLOWERS
FOLLOW BY EMAIL
Simple theme. Powered by Blogger .Details
Copyright © 2024 ArchiveBay.com. All rights reserved. Terms of Use | Privacy Policy | DMCA | 2021 | Feedback | Advertising | RSS 2.0