This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <queue> | |
using namespace std; | |
struct TreeNode { | |
int val; | |
TreeNode *left; | |
TreeNode *right; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <sstream> | |
#include <iomanip> | |
using namespace std; | |
static const int hexStrLen() { return sizeof(int)*2; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
struct TreeNode { | |
int val; | |
TreeNode *left; | |
TreeNode *right; | |
TreeNode(int x) : val(x), left(NULL), right(NULL) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <unordered_map> | |
#include <unordered_set> | |
#include <queue> | |
using namespace std; | |
typedef unordered_map<char, unordered_set<char>> GraphMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <unordered_set> | |
using namespace std; | |
int missingNumber(vector<int>& nums) { | |
int len=nums.size(); | |
int res = (len*(len+1))/2; | |
for (int val : nums) res -= val; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <unordered_set> | |
using namespace std; | |
int missingNumber(vector<int>& nums) { | |
int num=nums.size(); | |
for (int i=0; i<nums.size(); ++i) | |
num ^= (i ^ nums[i]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <unordered_set> | |
using namespace std; | |
int missingNumber(vector<int>& nums) { | |
int xorAll=0, xorMissing=0, len=nums.size(); | |
for (int i=0; i<len; ++i) xorMissing ^= nums[i]; | |
for (int i=0; i<len+1; ++i) xorAll ^= i; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <unordered_set> | |
using namespace std; | |
int missingNumber(vector<int>& nums) { | |
unordered_set<int> s; | |
for (int n : nums) s.insert(n); | |
for (int i=0; i<=nums.size(); ++i) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <unordered_map> | |
using namespace std; | |
void combinations(string& letters, string& comb, bool odd, char oddch, vector<string>& res) { | |
if (letters.size() == 0) { | |
string rev = comb; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <unordered_map> | |
using namespace std; | |
bool canPermutePalindrome(string s) { | |
unordered_map<char, int> m; | |
bool odd = (s.size() %2 != 0); | |
int countOdd=0; |