This file contains hidden or 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<unordered_set> | |
using namespace std; | |
struct Node | |
{ | |
int data; | |
Node *next; | |
This file contains hidden or 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> | |
using namespace std; | |
bool isSubstring(const string &s1, const string &s2) | |
{ | |
return s1.find(s2) != string::npos; | |
} | |
bool isRotation(const string &s1, const string &s2) |
This file contains hidden or 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> | |
using namespace std; | |
const int M = 3; | |
const int N = 4; | |
void setZeros(int matrix[][N]) | |
{ | |
int row[M/sizeof(int)+1]{}; |
This file contains hidden or 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> | |
using namespace std; | |
const int N = 4; | |
void rotate(int matrix[][N]) | |
{ | |
for (int i = 0; i < N/2; i++) { | |
for (int j = i; j < N-1-i; j++) { |
This file contains hidden or 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> | |
string compress(const string &s) | |
{ | |
string ns{}; | |
char last = s[0]; | |
unsigned count = 1; | |
for (int i = 1; i <= s.size(); i++) { | |
if (i != s.size() && s[i] == last) | |
count++; |
This file contains hidden or 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> | |
using namespace std; | |
void replace(char *s, unsigned l) | |
{ | |
if (s == nullptr) return; | |
unsigned sp = 0; | |
for (int i = 0; i < l; i++) | |
if (s[i] == ' ') |
This file contains hidden or 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> | |
using namespace std; | |
unsigned const NUM_CHAR = 256; | |
bool isPermutation1(string str1, string str2) | |
{ | |
sort(str1.begin(), str1.end()); | |
sort(str2.begin(), str2.end()); |
This file contains hidden or 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> | |
void reverse(char *str) { | |
if (str == nullptr) return; | |
// find the end of the string | |
char *end = str; | |
char temp; | |
while (*end != '\0') ++end; | |
--end; |
This file contains hidden or 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> | |
const unsigned NUM_CHAR = 256; | |
bool hasAllUniqueChar (std::string s) | |
{ | |
if (s.size() > NUM_CHAR) return false; | |
// init array | |
unsigned array[NUM_CHAR/sizeof(int)+1] = {}; |
This file contains hidden or 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 "stdio.h" | |
#include "stdlib.h" | |
#include "string.h" | |
/* Sample Input *** input_vectors.txt | |
0 1 | |
1 1 | |
0 1 | |
1 1 | |
0 1 |