class Solution {
public:
vector<int>twoSum(vector<int>& nums,int target){
unordered_map<int,int>hash;for(int i =0; i < nums.size(); i++){int t = target - nums[i];if(hash.count(t))return{i, hash[t]};
hash[nums[i]]= i;}return{};}};
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode*addTwoNumbers(ListNode* l1, ListNode* l2){
ListNode* dummy = new ListNode(-1);
ListNode* pre = dummy;int carry =0;while(l1 || l2){int res = carry;int a = l1 ? l1->val :0;int b = l2 ? l2->val :0;
res += a + b;
carry = res /10;int t = res %10;
pre->next = new ListNode(t);
pre = pre->next;if(l1) l1 = l1->next;if(l2) l2 = l2->next;}if(carry){
pre->next = new ListNode(1);}return dummy->next;}};
class Solution {
public:intlengthOfLongestSubstring(string s){
unordered_map<char,int>hash;int res =0;int i, j;for(i =0, j =0; j < s.size(); j ++){if(++ hash[s[j]]>1){while(i < j){
hash[s[i]]--;
i ++;if(hash[s[j]]==1)break;}}
res =max(res, j - i +1);}return res;}};
class Solution {
public:
string longestPalindrome(string s){int len =0;
string res ="";for(int i =0; i < s.size(); i ++){//偶数int l = i, r = i +1;while(l >=0&& r < s.size()&& s[l]== s[r]) l --, r ++;if(r - l -1> len){
len = r - l -1;
res = s.substr(l +1, len);}//奇数
l = i -1, r = i +1;while(l >=0&& r < s.size()&& s[l]== s[r]) l --, r ++;if(r - l -1> len){
len = r - l -1;
res = s.substr(l +1, len);}}return res;}};
class Solution {
public:
string convert(string s,int numRows){if(numRows ==1)return s;
vector<string>row(min((int)s.size(), numRows));int curRow =0;
bool down = false;for(auto c : s){
row[curRow]+= c;if(curRow ==0|| curRow == numRows -1) down =!down;
curRow += down ?1:-1;}
string res;for(auto c : row){
res += c;}return res;}};
class Solution {
public:intreverse(int x){int res =0;int pop =0;while(x){
pop =(x %10);
x /=10;if(res > INT_MAX /10)return0;if(res < INT_MIN /10)return0;
res = res *10+ pop;}return res;}};
class Solution {
public:intmyAtoi(string str){int i =0;longlong res =0;int flag =1;while(i < str.size()&& str[i]==' ') i ++;if(str[i]=='-') flag =-1, i ++;elseif(str[i]=='+') flag =1, i ++;while(i < str.size()&& str[i]>='0'&& str[i]<='9'){
res = res *10+ str[i ++]-'0';if(res >=2147483648){if(flag ==1)return INT_MAX;elsereturn INT_MIN;}}return res * flag;}};
class Solution {
public:
bool isPalindrome(int x){int xx = x;longlong p =0;if(x <0||(x %10==0&& x !=0))return false;while(x){
p = p *10+ x %10;
x /=10;}return p == xx;}};
class Solution {
public:
vector<vector<int>>f;int n, m;
bool isMatch(string s, string p){
n = s.size();
m = p.size();
f = vector<vector<int>>(n +1, vector<int>(m +1,-1));returndp(0,0, s, p);}
bool dp(int x,int y, string s, string p){if(f[x][y]!=-1)return f[x][y];if(y == m)return f[x][y]= x == n;
bool first_match = x < n &&(s[x]== p[y]|| p[y]=='.');
bool res;if(y +1< m && p[y +1]=='*'){
res =dp(x, y +2, s, p)|| first_match &&dp(x +1, y, s, p);}else{
res = first_match &&dp(x +1, y +1, s, p);}return f[x][y]= res;}};