leetcode代码200题c++

  • i3_701749
    了解作者
  • 78.3KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-13 23:54
    上传日期
leetcode代码200题,语言c++。用了一个月做了下leetode。都是AC代码。
leetcode.rar
  • Combinations .txt
    445B
  • Maximum Product Subarray .txt
    479B
  • Contains Duplicate.txt
    303B
  • Combination Sum III.txt
    470B
  • Path Sum II .txt
    892B
  • Remove Duplicates from Sorted Array II .txt
    382B
  • Best Time to Buy and Sell Stock III .txt
    881B
  • Lowest Common Ancestor of a Binary Tree.txt
    1001B
  • Container With Most Water.txt
    420B
  • Maximum Subarray.txt
    269B
  • Pascal's Triangle II .txt
    268B
  • N-Queens II .txt
    663B
  • Flatten Binary Tree to Linked List.txt
    1.5KB
  • Climbing Stairs .txt
    285B
  • Palindrome Linked List .txt
    893B
  • Shortest Palindrome .txt
    496B
  • Best Time to Buy and Sell Stock IV .txt
    2KB
  • Best Time to Buy and Sell Stock II .txt
    379B
  • Implement strStr() .txt
    876B
  • Anagrams .txt
    464B
  • Restore IP Addresses .txt
    1.9KB
  • Minimum Window Substring.txt
    2.7KB
  • Binary Tree Right Side View .txt
    664B
  • Isomorphic Strings .txt
    432B
  • Maximum Gap.txt
    1.1KB
  • Minimum Depth of Binary Tree .txt
    1.4KB
  • First Missing Positive.txt
    629B
  • Add and Search Word - Data structure design.txt
    1.2KB
  • Max Points on a Line .txt
    1015B
  • single number.txt
    210B
  • Symmetric Tree .txt
    772B
  • Next Permutation .txt
    1.1KB
  • Reverse Linked List .txt
    478B
  • Regular Expression Matching .txt
    860B
  • Intersection of Two Linked Lists.txt
    1001B
  • Sort List .txt
    974B
  • Sudoku Solver .txt
    970B
  • Implement Stack using Queues .txt
    1.2KB
  • 4Sum.txt
    1.1KB
  • Count Primes.txt
    543B
  • Subsets .txt
    458B
  • Maximum Depth of Binary Tree .txt
    387B
  • Remove Duplicates from Sorted List II .txt
    833B
  • 3Sum.txt
    906B
  • Merge k Sorted Lists.txt
    1.3KB
  • Divide Two Integers.txt
    992B
  • Jump Game .txt
    530B
  • Number of Islands .txt
    652B
  • Jump Game II .txt
    479B
  • Binary Tree Paths .txt
    1.1KB
  • Power of Two.txt
    236B
  • Convert Sorted Array to Binary Search Tree .txt
    623B
  • Remove Duplicates from Sorted List .txt
    553B
  • Find Minimum in Rotated Sorted Array II .txt
    360B
  • Balanced Binary Tree .txt
    572B
  • Binary Tree Level Order Traversal.txt
    877B
  • Longest Common Prefix .txt
    727B
  • Different Ways to Add Parentheses.txt
    1.2KB
  • Binary Tree Level Order Traversal II .txt
    1014B
  • Construct Binary Tree from Preorder and Inorder Traversal .txt
    985B
  • Binary Tree Zigzag Level Order Traversal .txt
    1.1KB
  • Rotate Image .txt
    649B
  • Gas Station.txt
    585B
  • Longest Valid Parentheses .txt
    503B
  • Same Tree .txt
    693B
  • Find Minimum in Rotated Sorted Array .txt
    378B
  • Distinct Subsequences .txt
    450B
  • Count and Say .txt
    834B
  • Unique Binary Search Trees .txt
    306B
  • Set Matrix Zeroes .txt
    1.1KB
  • Delete Node in a Linked List.txt
    316B
  • 3Sum Closest .txt
    701B
  • Course Schedule II .txt
    747B
  • Word Break II .txt
    1014B
  • Remove Element .txt
    297B
  • Unique Paths II .txt
    611B
  • Word Ladder .txt
    1.4KB
  • Excel Sheet Column Title.txt
    258B
  • Single Number III .txt
    571B
  • Search a 2D Matrix .txt
    491B
  • Insert Interval .txt
    1.7KB
  • Basic Calculator II.txt
    1.7KB
  • String to Integer (atoi) .txt
    903B
  • Search for a Range.txt
    934B
  • Search Insert Position.txt
    423B
  • Populating Next Right Pointers in Each Node .txt
    1.4KB
  • Find Peak Element .txt
    555B
  • Plus One.txt
    465B
  • Palindrome Partitioning II.txt
    908B
  • Reverse Words in a String.txt
    1019B
  • Word Ladder II .txt
    1.7KB
  • Construct Binary Tree from Inorder and Postorder Traversal .txt
    982B
  • Contains Duplicate II .txt
    462B
  • Unique Paths .txt
    440B
  • Add Binary .txt
    743B
  • Kth Largest Element in an Array .txt
    623B
  • Course Schedule .txt
    664B
  • Palindrome Partitioning .txt
    925B
  • Permutations II.txt
    639B
  • Word Search II.txt
    4.3KB
内容介绍
class Solution { public: struct node { bool is; node *next[26]; }; vector<string>res; vector<vector<char>>board; node *root; set<string> st; int row; int col; void buildtrie(string s) { node *head=root; int len=s.length(); for(int i=0;i<len;i++) { if(head->next[s[i]-'a']==NULL) { node *p=(node*)malloc(sizeof(node)); p->is=false; for(int i=0;i<26;i++) p->next[i]=NULL; head->next[s[i]-'a']=p; } head=head->next[s[i]-'a']; } head->is=true; } bool find(string s) { int len=s.length(); if(len==0) return false; node *ptr=root; int i=0; while(i<len&&ptr->next[s[i]-'a']) { ptr=ptr->next[s[i]-'a']; i++; } if(i==len&&ptr!=NULL&&ptr->is==true) return true; return false; } bool isprefix(string s) { int len=s.length(); if(len==0) return true; node *ptr=root; int i=0; while(i<len&&ptr->next[s[i]-'a']) { ptr=ptr->next[s[i]-'a']; i++; if(ptr==NULL) break; } if(i==len) return true; return false; } void dfs(vector<vector<bool>> visit,string s,int x,int y) { int k[]={-1,0,1,0}; int l[]={0,-1,0,1}; visit[x][y]=true; if(isprefix(s)) { for(int i=0;i<4;i++) { int xx=x+k[i]; int yy=y+l[i]; if(xx>=0&&xx<row&&yy>=0&&yy<col&&visit[xx][yy]==false) { s.push_back(board[xx][yy]); if(find(s)) st.insert(s); if(isprefix(s)) dfs(visit,s,xx,yy); s.pop_back(); } } } } vector<string> findWords(vector<vector<char>>& board1, vector<string>& words) { board=board1; root=(node*)malloc(sizeof(node)); root->is=false; for(int i=0;i<26;i++) root->next[i]=NULL; for(int i=0;i<words.size();i++) buildtrie(words[i]); row=board.size(); col=board[0].size(); vector<vector<bool>> visit(row,vector<bool>(col,false)); string s=""; for(int i=0;i<row;i++) { for(int j=0;j<col;j++) { s.push_back(board[i][j]); if(find(s)) st.insert(s); if(isprefix(s)) dfs(visit,s,i,j); s.pop_back(); } } set<string>::iterator it; for( it=st.begin();it!=st.end();it++) res.push_back(*it); return res; } }; class Solution { public: struct node { bool is; node *next[26]; }; vector<string>res; vector<vector<char>>board; node *root; set<string> st; int row; int col; void buildtrie(string s) { node *head=root; int len=s.length(); for(int i=0;i<len;i++) { if(head->next[s[i]-'a']==NULL) { node *p=(node*)malloc(sizeof(node)); p->is=false; for(int i=0;i<26;i++) p->next[i]=NULL; head->next[s[i]-'a']=p; } head=head->next[s[i]-'a']; } head->is=true; } bool find(string s) { int len=s.length(); if(len==0) return false; node *ptr=root; int i=0; while(i<len&&ptr->next[s[i]-'a']) { ptr=ptr->next[s[i]-'a']; i++; } if(i==len&&ptr!=NULL&&ptr->is==true) return true; return false; } bool isprefix(string s) { int len=s.length(); if(len==0) return true; node *ptr=root; int i=0; while(i<len&&ptr->next[s[i]-'a']) { ptr=ptr->next[s[i]-'a']; i++; if(ptr==NULL) break; } if(i==len) return true; return false; } void dfs(vector<vector<bool>> visit,string s,int x,int y) { int k[]={-1,0,1,0}; int l[]={0,-1,0,1}; visit[x][y]=true; if(isprefix(s)) { for(int i=0;i<4;i++) { int xx=x+k[i]; int yy=y+l[i]; if(xx>=0&&xx<row&&yy>=0&&yy<col&&visit[xx][yy]==false) { string tt=s+board[xx][yy]; //s.push_back(board[xx][yy]); if(find(tt)) st.insert(tt); if(isprefix(tt)) dfs(visit,s+board[xx][yy],xx,yy); } } } } vector<string> findWords(vector<vector<char>>& board1, vector<string>& words) { board=board1; root=(node*)malloc(sizeof(node)); root->is=false; for(int i=0;i<26;i++) root->next[i]=NULL; for(int i=0;i<words.size();i++) buildtrie(words[i]); row=board.size(); col=board[0].size(); vector<vector<bool>> visit(row,vector<bool>(col,false)); string s=""; for(int i=0;i<row;i++) { for(int j=0;j<col;j++) { s.push_back(board[i][j]); if(find(s)) st.insert(s); if(isprefix(s)) dfs(visit,s,i,j); s.pop_back(); } } set<string>::iterator it; for( it=st.begin();it!=st.end();it++) res.push_back(*it); return res; } };
评论
    相关推荐
    • leetcode c++ 分类高清版 有答案
      leetcode c++ 分类高清版 有答案 leetcode c++ 分类高清版 有答案 leetcode c++ 分类高清版 有答案 leetcode c++ 分类高清版 有答案leetcode c++ 分类高清版 有答案
    • leetcode2sumc-LeetCode:C++11中的LeetCode解决方案
      C++ 11 中的 LeetCode 解决方案。 不。 标题 解决方案 困难 1 简单的 2 中等的 4 难的 5 中等的 20 简单的 21 简单的 35 简单的 43 中等的 53 简单的 63 中等的 64 中等的 92 简单的 121 简单的 129 中等的 144 简单...
    • leetcode本地c++11开发组件
      方便本地开发测试,专注于实现提交函数,初版完善有限见量
    • leetcode答案-leetcode:leetcode-c++answers
      leetcode 答案leetcode leetcode-c++answers leetcode 的答案....更新中
    • leetcode-leetcode:leetcode的最佳C++解决方案
      C++ solutions for the leetcode 这是我自己写的leetcode的题解,目前已经完成了70%左右,后续部分会很快更新 这里放上来的代码都能保证是最优解(复杂度最优) 当然有些题目因为测试数据等原因可能会和统计中最快的...
    • leetcode:leetcodeC++代码
      leetcode 使用C++解决leetcode问题, //oj.leetcode.com/ 简单的介绍 编译标准 ISO C++11
    • LeetCode C++全解
      1. Introduction 2. Array i. Remove Element ii. Remove Duplicates from Sorted Array iii. Plus One iv. Pascal's Triangle v. Merge Sorted Array vi. Sum vii. Find Minimum in ...viii....ix....x....xi....xii....xiii....xiv....
    • leetcodepushfront-leetcode:C++中的leetcode
      C++中的leetcode 重要:15, 74, 105, 200, 236, 39 & 40 & 46, 43, 55, 81, 90, 96, 131 重做:31、33 binary_search 变种:旋转,重复 cp: // string string strNew = str + 'c' string strNew = str + "car" ...
    • GaussDB_100_1.0.1-DATABASE-REDHAT-64bit.tar.gz
      guassdb100在redhat上安装包,单机部署的包,安装步骤请看我的文中介绍,经过大量实验搭建总结出来的文档