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
| // Enum (appType) <=> string (dbType) | |
| public class RmqMessageStatusCustomType : IUserType | |
| { | |
| public new bool Equals(object x, object y) | |
| { | |
| if (x == null && y == null) | |
| return true; | |
| if (x == null || y == null) | |
| return false; |
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
| /** | |
| * Definition for singly-linked list. | |
| * struct ListNode { | |
| * int val; | |
| * ListNode *next; | |
| * ListNode() : val(0), next(nullptr) {} | |
| * ListNode(int x) : val(x), next(nullptr) {} | |
| * ListNode(int x, ListNode *next) : val(x), next(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
| class Solution { | |
| public: | |
| int lengthOfLongestSubstring(string s) { | |
| unordered_map<char, int> map; | |
| int maxLength = 0; | |
| int j = 0; | |
| for (int i = 0; i < s.length(); i++) { | |
| if (map.find(s[i]) != map.end()) { | |
| if (j < map[s[i]] + 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
| string longestPalindrome(string s) { | |
| int l = 0; | |
| int r = 0; | |
| string result = ""; | |
| for (int i = 0; i < s.length(); i++) { | |
| l = r = 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 isValid(string s) { | |
| if (s.length() < 1 || s.at(0) == ')' || s.at(0) == ']' || s.at(0) == '}') { | |
| return false; | |
| } | |
| // 1. create stack object | |
| stack<char> pStack; | |
| // 2. iterate "s" | |
| for (int i = 0; i < s.length(); 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
| /** | |
| * Definition for singly-linked list. | |
| * struct ListNode { | |
| * int val; | |
| * ListNode *next; | |
| * ListNode() : val(0), next(nullptr) {} | |
| * ListNode(int x) : val(x), next(nullptr) {} | |
| * ListNode(int x, ListNode *next) : val(x), next(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
| int removeElement(vector<int>& nums, int val) { | |
| int l = 0; | |
| int r = nums.size() - 1; | |
| while (l <= r) { | |
| // if char at l'th element is equal to val, | |
| // assign char at r'th element to th one at l'th element | |
| if (nums[l] == val) { | |
| nums[l] = nums[r]; |
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
| /** | |
| * KMP (Knuth Morris Pratt) Pattern Searching | |
| **/ | |
| int strStr(string haystack, string needle) { | |
| // return 0 if needle is empty string | |
| if (needle.length() == 0) return 0; | |
| // find sub-patterns in needle | |
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
| int searchInsert(vector<int>& nums, int target) { | |
| int l = 0; | |
| int r = nums.size() - 1; | |
| // since nums is sorted, we can take an advantage of binary search | |
| while (l <= r) { | |
| int m = (l + r) / 2; | |
| if (nums[m] == target) { | |
| return m; |
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
| ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { | |
| if (!headA || !headB) return nullptr; | |
| ListNode* a = headA; | |
| ListNode* b = headB; | |
| while (a != b) { | |
| a = (a) ? a->next : headB; | |
| b = (b) ? b->next : headA; |
OlderNewer