├── 234. Palindrome Linked List.cpp ├── 392.Is Subsequence.cpp ├── 42.Trapping Rain Water.cpp ├── 54. Spiral Matrix.cpp └── 832. Flipping an Image.cpp /234. Palindrome Linked List.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for singly-linked list. 3 | * struct ListNode { 4 | * int val; 5 | * ListNode *next; 6 | * ListNode() : val(0), next(nullptr) {} 7 | * ListNode(int x) : val(x), next(nullptr) {} 8 | * ListNode(int x, ListNode *next) : val(x), next(next) {} 9 | * }; 10 | */ 11 | class Solution { 12 | public: 13 | bool isPalindrome(ListNode* head) { 14 | vector a; 15 | while(head != NULL) 16 | { 17 | a.push_back(head->val); 18 | head = head->next; 19 | } 20 | int high = a.size()-1; 21 | for(int i=0;i& height) { 4 | int size = height.size(); 5 | vector left(size); 6 | vector right(size); 7 | int max_val = INT_MIN; 8 | for(int i=0;i=0;i--) 15 | { 16 | max_val = max(max_val,height[i]); 17 | right[i] = max_val; 18 | } 19 | int ans = 0; 20 | for(int i=0;i spiralOrder(vector>& matrix) { 4 | int top = 0; 5 | int left = 0; 6 | int bot = matrix.size()-1; 7 | int right = matrix[0].size()-1; 8 | vector ans; 9 | int d = 1; 10 | while(top <=bot && left<=right) 11 | { 12 | if(d==1) 13 | { 14 | for(int i=left;i<=right;i++) 15 | { 16 | ans.push_back(matrix[top][i]); 17 | } 18 | top++; 19 | } 20 | if(d==2) 21 | { 22 | for(int i=top;i<=bot;i++) 23 | { 24 | ans.push_back(matrix[i][right]); 25 | } 26 | right--; 27 | } 28 | if(d==3) 29 | { 30 | for(int i=right;i>=left;i--) 31 | { 32 | ans.push_back(matrix[bot][i]); 33 | } 34 | bot--; 35 | } 36 | if(d==4) 37 | { 38 | for(int i=bot;i>=top;i--) 39 | { 40 | ans.push_back(matrix[i][left]); 41 | } 42 | left++; 43 | } 44 | d++; 45 | if(d==5) 46 | { 47 | d=1; 48 | } 49 | } 50 | return ans; 51 | } 52 | }; 53 | -------------------------------------------------------------------------------- /832. Flipping an Image.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector> flipAndInvertImage(vector> image) { 4 | vector a; 5 | for(int i=0;i