LeetCode
昂德森科技
因为热爱,所以拼搏。
展开
-
leetcode Z字形变换
class Solution { public: string convert(string s, int numRows) { if(numRows==0||numRows==1) return s; string res; int n=2*numRows-2; for(int i=0;i<numRows;++i){ for(int j=0;j<s.size();++j){原创 2021-09-14 20:49:45 · 53 阅读 · 0 评论 -
13罗马数字转整数
class Solution { public: int romanToInt(string s){ unordered_map <char,int> hash; hash['I']=1;hash['V']=5; hash['X']=10;hash['L']=50; hash['C']=100;hash['D']=500; hash['M']=1000; int len=s.size(); int res=0;原创 2021-09-06 22:06:50 · 60 阅读 · 0 评论 -
最长回文子串
class Solution { public: string longestPalindrome(string s) { if(s.empty() || s.size() < 2) { return s; } //对原始字符串做处理,将abc变成#a#b#c# string tmp = "#"; for(char c : s) { tmp += c;转载 2021-09-05 22:43:05 · 71 阅读 · 0 评论 -
盛水最多的容器
class Solution { public: int maxArea(vector<int>& height) { if(height.size()<=1){ return -1; } int i=0,j=height.size()-1,res=0; while(i<j){ int h=min(height[i],height[j]);原创 2021-09-01 20:08:03 · 60 阅读 · 0 评论 -
1727 重新排列后最大子矩阵
class Solution { public: int largestSubmatrix(vector<vector<int>>& matrix) { int n = matrix.size(), m = matrix[0].size(); for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ if(j>原创 2021-08-22 22:10:26 · 70 阅读 · 0 评论 -
leetcode 79单词搜索
class Solution { public: bool exist(vector<vector<char>>& board, string word) { //row for(int i = 0; i < board.size(); i++) //col for(int j = 0; j < board[i].size(); j++) //从word下标为0开始遍历原创 2021-08-21 22:20:50 · 67 阅读 · 0 评论