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 <cstring> | |
| using namespace std; | |
| string removeDuplicates(string s) { | |
| bool chs[512]; | |
| memset(chs, false, sizeof chs); | |
| int j = 0; | |
| for(int i = 0; i < s.size(); 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
| bool isAnagaram(string s1, string s2) { | |
| sort(s1.begin(), s1.end()); | |
| sort(s2.begin(), s2.end()); | |
| return s1==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
| void rotate90(vector<vector<int> >& image) { | |
| int n = image.size(); | |
| for(int i = 0; i < n; i++) { | |
| for(int j = 0; j < n; j++) { | |
| swap(image[i][j], image[n-j-1][n-i-1]); | |
| } | |
| } | |
| for(int i = 0; i < n/2; 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
| void resetMtrx(vector<vector<int> >& mtrx) { | |
| if(mtrx.size() == 0 || mtrx[0].size() == 0) return; | |
| int rows[mtrx.size()], cols[mtrx[0].size()]; | |
| memset(rows, 1, sizeof rows); | |
| memset(cols, 1, sizeof cols); | |
| for(int i = 0; i < mtrx.size(); 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
| bool isSubstring(string s1, string s2) { | |
| return (s1.find(s2) != string::npos); | |
| } | |
| bool isRotated(string s1, string s2) { | |
| string tmp = s1+s1; | |
| return isSubstring(tmp, 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
| struct List { | |
| int a; | |
| List* nxt; | |
| List(int a) { | |
| this->a = a; | |
| nxt = NULL; | |
| } | |
| void insert(int s) { |
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
| void remove(node* nd) { | |
| if(nd == NULL || nd->nxt == NULL) return; // It should be in the middle | |
| node* lnk1 = nd, *lnk2 = nd->nxt; | |
| while(lnk2->nxt) { | |
| swap(lnk1->d, lnk2->d); | |
| lnk1 = lnk1->nxt; | |
| lnk2 = lnk2->nxt; |
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
| node* sum(node* num1, node* num2) { | |
| node* l1 = num1, *l2 = num2; | |
| node* res = new node(0); | |
| int rem = 0; | |
| while(l1 && l2) { | |
| int num = l1->d+l2->d+rem; | |
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 "list.h" // See problem #8 | |
| node* getLoopStart(node* lst) { | |
| node *lnk1 = lst, *lnk2 = lst; | |
| while(lnk2->nxt) { | |
| lnk1 = lnk1->nxt; | |
| lnk2 = lnk2->nxt->nxt; | |
| if(lnk2 == NULL) return NULL; |
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<vector> | |
| #define STACK_IS_EMPTY -1 | |
| class CustomStack { | |
| private: | |
| vector<int> stck; | |
| vector<int> mn; | |
| public: |