![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
雪可问春风
这个作者很懒,什么都没留下…
展开
-
leetcode221.最大正方形
可以使用动态规划降低时间复杂度。用 dp(i,j) 表示以 (i,j)为右下角,且只包含 111 的正方形的边长最大值。能计算出所有 dp(i,j)的值,那么其中的最大值即为矩阵中只包含 111 的正方形的边长最大值,其平方即为最大正方形的面积。如果该位置的值是 111,则 dp(i,j)的值由其上方、左方和左上方的三个相邻位置的 dp值决定。此外,还需要考虑边界条件。如果 i 和 j中至少有一个为 0,则以位置 (i,j)为右下角的最大正方形的边长只能是 1,因此 dp(i,j)=1。原创 2023-10-16 18:07:05 · 378 阅读 · 0 评论 -
300. 最长递增子序列
maxlen(k) = max{maxlen(i):0 <= i < k 且。若找不到这样的i,则maxlen(k) = 1。,且长度最大的那个上升子序列的长度再加1。maxlen(k)的值,就是在。后就能行程一个更长的上升子序列。为重点的最长上升子序列的长度。maxlen(K)表示以。原创 2023-10-08 15:09:58 · 122 阅读 · 0 评论 -
120.三角形最小路径和
f(i,j)=f(i,j) =f(i,j)= 从 (i,j)(i,j)(i,j) 到达最后一行的最小路径和。既然我们从下而上求解,那么我们就只能利用下面位置的值。原创 2023-10-07 17:12:41 · 209 阅读 · 0 评论 -
oj_01_简单计算器
题目:读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值。Input测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符,整数和运算符之间用一个空格分隔。没有非法表达式。当一行中只有0时输入结束,相应的结果不要输出。Output对每个测试用例输出1行,即该表达式的值,精确到小数点后2位。Sample Input1 + 24 + 2 * 5 - 7 / 110Sample Output3.0013.36**代码#include <原创 2021-09-23 14:46:54 · 276 阅读 · 0 评论 -
c++中获取数组的长度
c++中没有定义该函数,但可以使用sizeof()函数int a[20];cout<<sizeof(a)/sizeof(a[0]);原创 2021-08-20 14:56:27 · 124 阅读 · 0 评论 -
oj_02_Basic Data Struct(hdu 5929)
题目Mr. Frog learned a basic data structure recently, which is called stack.There are some basic operations of stack:∙ PUSH x: put x on the top of the stack, x must be 0 or 1.∙ POP: throw the element which is on the top of the stack.Since it is too simpl原创 2021-09-23 14:43:51 · 94 阅读 · 0 评论 -
oj_03_pots题解(BFS应用)
题目:You are given two pots, having the volume of A and B liters respectively. The following operations can be performed:FILL(i) fill the pot i (1 ≤ i ≤ 2) from the tap;DROP(i) empty the pot i to the drain;POUR(i,j) pour from pot i to pot原创 2021-09-23 14:28:58 · 320 阅读 · 0 评论 -
Dijkstra算法-求最短路径
输入6 81 3 101 5 301 6 1002 3 53 4 504 6 105 6 605 4 20输出代码#include <cstring>#include "iostream"#include "vector"using namespace std;//Dijkstra//使用邻接矩阵来存储图//记录起点到每个顶点的最短路径的信息struct Dis{ string path; int value; bool v.原创 2021-09-26 15:06:36 · 338 阅读 · 0 评论 -
leetcode 第4题-寻找两个正序数组中位数
c++:因为数组有序,则无需排序,维护两个指针,依次移动,时间复杂度O(m + n),同一个程序,有时候显示16ms,有时候44ms,离谱class Solution {public: double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { // 因为数组有序,则无需排序,维护两个指针,依次移动,时间复杂度O(m + n) int p原创 2022-04-13 17:21:46 · 1484 阅读 · 0 评论 -
leetcode 第三题-无重复字符的最长子串 ps:bug:ERROR: AddressSanitizer: heap-use-after-free on address
c++ 使用hashmap+ 滑动窗口踩坑:map的存储不是按照插入的顺序来进行存储的,而是经过排序的,因此不能使用hashmap.erase(hashmap.begin(),iter)来进行范围删除时间复杂度为O( n2n^{2}n2)class Solution {public: int lengthOfLongestSubstring(string s) { map<char, int> hashmap; map<char, int>原创 2022-04-08 16:29:54 · 817 阅读 · 0 评论 -
leetcode第二题 -两数相加
c++ 维护一个进位变量,速度还可以链表的东西,有点忘了class Solution {public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode *ans = new ListNode(-1); ListNode *cursor = ans; int t = 0; while (l1 != nullptr || l2 != nullptr ||原创 2022-04-07 15:42:16 · 756 阅读 · 0 评论 -
Leetcode 第一题-两数之和
评论比较有意思,刷题什么的飒飒shui有人相爱,有人夜里开车看海,有人leetcode第一题都做不出来。每当我别的题不会时,我就回来刷第一题。尝试用c++和py解c++ 暴力解法class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { int nums_size = nums.size(); for(int i = 0;i <原创 2022-04-07 15:38:37 · 1267 阅读 · 0 评论