上一页 1 2 3 4 5 6 ··· 19 下一页
摘要: 题目 分析 直接暴力搜索 代码 1 class Solution { 2 public: 3 string longestCommonPrefix(vector<string>& strs) { 4 string res ; 5 // i 控制列,j 控制l行 6 for(int i = 0;i < 阅读全文
posted @ 2022-03-15 17:07 Uitachi 阅读(25) 评论(0) 推荐(0)
摘要: 题目 分析 受LeetCode 12题目影响,一时没反应过来用哈希存储,虽说难度是简单,还没上一道做的舒服。。。。 这道题目关键在于特判下4的特殊情况,就是后一个字母比当前字母要大时情况要特殊判断下 代码 1 class Solution { 2 public: 3 int romanToInt(s 阅读全文
posted @ 2022-03-15 16:03 Uitachi 阅读(28) 评论(0) 推荐(0)
摘要: 题目 分析 模拟 + 找规律 代码 暴力模拟 1 class Solution { 2 public: 3 string intToRoman(int num) { 4 // string roman[] ={"M","D","C","L","X","V","I"}; 5 int a[] = {30 阅读全文
posted @ 2022-03-08 22:50 Uitachi 阅读(34) 评论(0) 推荐(0)
摘要: 题目 分析 这题出的太精巧了,本人的话只会无脑暴力搜索,但实际上用双指针。其严格证明见: https://www.acwing.com/solution/content/100/ 这题应该是贪心算法,但没看出要贪心什么,没有直觉。。。 代码 1 class Solution { 2 public: 阅读全文
posted @ 2022-03-07 22:50 Uitachi 阅读(19) 评论(0) 推荐(0)
摘要: 题目 分析 代码 LeetCode7.整数反转 的变形 1 class Solution { 2 public: 3 bool isPalindrome(int x) { 4 if(x < 0) return false; 5 int n = 0,o = x; 6 while(x){ 7 if(n 阅读全文
posted @ 2022-03-06 21:12 Uitachi 阅读(28) 评论(0) 推荐(0)
摘要: 题目 分析 简单模拟 代码 1 class Solution { 2 public: 3 int myAtoi(string s) { 4 //首先去除开头空格 5 int k = 0; 6 while(k < s.size() && s[k] == ' '){k++;} 7 8 int flag 阅读全文
posted @ 2022-03-06 11:32 Uitachi 阅读(29) 评论(0) 推荐(0)
摘要: 题目 分析 取出每一位(取余除以十) 代码 1 class Solution { 2 public: 3 int reverse(int x) { 4 long long int r = 0; 5 while(x){ 6 r = r * 10 + x % 10; 7 x /= 10; 8 } 9 i 阅读全文
posted @ 2022-03-05 22:09 Uitachi 阅读(31) 评论(0) 推荐(0)
摘要: 题目 分析 对于这类问题,我们采用dx, dy 方向数组来存储,并且将顺时针方向定义为1,2,3,0 撞墙的情况有两种,一个是出去,一个是走重复的格子 代码 1 #include<iostream> 2 using namespace std; 3 4 const int N = 110; 5 in 阅读全文
posted @ 2022-03-04 15:12 Uitachi 阅读(118) 评论(0) 推荐(0)
摘要: 题目 分析 Manacher 算法算法比较复杂,不考虑,我们只学习中心扩散算法和DP 法一、采用中心扩散法 也就是枚举每个点,找到最长的回文串。回文串分为两种:奇数和偶数长度的回文串。其中奇数的串是关于中心对称的,偶数的串是左右相同。 因为要求最长的回文子串,但是我们并不清楚最长的回文子串的长度是奇 阅读全文
posted @ 2022-03-03 22:19 Uitachi 阅读(40) 评论(0) 推荐(0)
摘要: 题目 分析 此题目转换为求两个有序数组的第 K 小的数 参考 https://www.acwing.com/solution/content/50/ 代码 1 class Solution { 2 public: 3 double findMedianSortedArrays(vector<int> 阅读全文
posted @ 2022-03-01 17:34 Uitachi 阅读(32) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 ··· 19 下一页