上一页 1 ··· 5 6 7 8 9 10 11 12 13 下一页
摘要: 1.力扣595.大的国家 i. 1 # Write your MySQL query statement below 2 select name,population,area from World 3 where area >= 3000000 or population >= 25000000; 阅读全文
posted @ 2022-08-02 10:58 balabalahhh 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 三种情况: 1.左半部分(leftsum)最大(与右边不连续,不一定包括mid) 2.右半部分(rightsum)最大(与左边不连续,不一定包括mid+1) 3.左右部分联合最大(左右两边连续,包括mid) 1和2是前面返回的(与另一边不连续 !!!,左半部分不一定是包含mid 以mid结尾的,右半 阅读全文
posted @ 2022-08-01 12:23 balabalahhh 阅读(18) 评论(0) 推荐(0) 编辑
摘要: CommonPre函数:把字符串数组一分为二,分别求出左右两边数组的最长公共前后缀 left 和 right,然后将两者进行比较得到最终的 最长公共前后缀 1 class Solution { 2 public: 3 string longestCommonPrefix(vector<string> 阅读全文
posted @ 2022-08-01 10:48 balabalahhh 阅读(304) 评论(0) 推荐(0) 编辑
摘要: 1.剑指 Offer 14- II. 剪绳子 II 1 class Solution { 2 public: 3 int cuttingRope(int n) { 4 if(n <= 3) return n - 1; 5 long res = 1; 6 while(n > 4){ 7 n -= 3; 阅读全文
posted @ 2022-07-28 17:52 balabalahhh 阅读(19) 评论(0) 推荐(0) 编辑
摘要: 1.剑指 Offer 17. 打印从 1 到最大的 n 位数 1)直接列举(执行用时比分治短) 1 class Solution { 2 public: 3 vector<int> printNumbers(int n) { 4 vector<int> res; 5 int num = 0; 6 f 阅读全文
posted @ 2022-07-26 22:50 balabalahhh 阅读(19) 评论(0) 推荐(0) 编辑
摘要: 剑指 Offer 49. 丑数 1)会超时,数据范围只能到1200几 1 class Solution { 2 public: 3 int nthUglyNumber(int n) { 4 int k = 0,res; 5 for(int i = 1;;i ++){ 6 if(isUglyNum(i 阅读全文
posted @ 2022-07-25 22:23 balabalahhh 阅读(11) 评论(0) 推荐(0) 编辑
摘要: 1.剑指 Offer 37. 序列化二叉树 1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * Tre 阅读全文
posted @ 2022-07-24 22:12 balabalahhh 阅读(21) 评论(0) 推荐(0) 编辑
摘要: 1.剑指 Offer 59 - I. 滑动窗口的最大值 单调队列 1 class Solution { 2 public: 3 vector<int> maxSlidingWindow(vector<int>& nums, int k) { 4 vector<int> res; 5 deque<in 阅读全文
posted @ 2022-07-23 11:53 balabalahhh 阅读(12) 评论(0) 推荐(0) 编辑
摘要: “如果一个选手比你小还比你强,你就可以退役了。”——单调队列的原理 作者写的很好,例子也很形象 : 算法学习笔记(66): 单调队列 - 知乎 (zhihu.com) 可以通过做这道题来理解 https://leetcode-cn.com/problems/sliding-window-maximu 阅读全文
posted @ 2022-07-23 10:27 balabalahhh 阅读(45) 评论(0) 推荐(0) 编辑
摘要: 剑指 Offer 67. 把字符串转换成整数 注意一下出界的情况 1 class Solution { 2 public: 3 int strToInt(string str) { 4 int len = str.size(); 5 if(len == 0) return 0; 6 int i = 阅读全文
posted @ 2022-07-22 22:22 balabalahhh 阅读(18) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 下一页