![](https://img-blog.csdnimg.cn/20191029092838925.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
[解题报告]
桑来93
time will tell
展开
-
[程序员代码面试指南] 求最大子矩阵的大小
[程序员代码面试指南] 求最大子矩阵的大小题目描述:给定一个整型的矩阵,其中只有0和1两种值.求其中 最大的全是1 的 矩形 区域的大小如: 1 1 1 0 最大区域为 3再如: 1 0 1 1 1 1 1 1 1 1 1 0 最大矩阵区域为 6分析:将矩阵看做一行一行的.求每一行为底的,每个位置往上 1 的个数.用高度数组 height 表示.对于每一次...原创 2018-12-27 22:51:11 · 219 阅读 · 0 评论 -
[程序员代码面试指南] 数组的异或和
定义数组的异或和的概念:数组中所有的数异或起来,得到的结果叫做数组的异或和,比如数组{3,2,1}的异或和是,321 = 0【题目】给定一个数组arr,你可以任意把arr分成很多不相容的子数组,你的目的是:分出来的子数组中,异或和为0的子数组最多。请返回:分出来的子数组中,异或和为0的子数组最多是多少?int MostXOR(vector<int>& arr) { v...原创 2019-03-19 22:30:02 · 2180 阅读 · 2 评论 -
[程序员代码面试指南] 最大值减去最小值小于或等于num的子数组数量
[程序员代码面试指南] 最大值减去最小值小于或等于num的子数组数量题目描述:给定数组arr和整数num,返回共有多少个子数组满足如下情况:max(arr[i..j])-min(arr[i..j])<=num分析:利用滑动窗口进行计算, [i..j] 用两个指针 i j 表示,其子数组.用两个双端数组分别维护这个窗口内的最大值和最小值从数组arr的每个位置开始扩张(max-...原创 2018-12-27 23:16:26 · 353 阅读 · 0 评论 -
[剑指Offer笔记]5_链表 printListFromTailToHead
[剑指Offer笔记]5_链表 printListFromTailToHead链表的一些操作链表的创建 / 插入节点 / 删除节点插入节点: 新建一个节点,分配空间!!!Example 1 往链表末尾添加一个节点// 添加一个节点到链表的末尾void AddToTail(ListNode **pHead, int value) { ListNode *pNew = new Li...原创 2018-11-25 08:56:18 · 1288 阅读 · 0 评论 -
[剑指Offer笔记]3_数组
[剑指Offer笔记]3_数组数组,字符串:连续空间链表,树:大量指针操作栈:与递归相关队列:广度优先算法相关数组O(1)时间读写元素;可以用数组实现 哈希表 ;有了哈希表可以实现O(1)查找!固定大小的数组,效率不高. STL 中的 vector先开辟一个小的空间,当空间不够时再分配更大的空间.每次为之前的2倍.使用动态数组要尽量计算减少改变容量大小的次数...原创 2018-11-25 08:55:01 · 125 阅读 · 0 评论 -
[剑指Offer笔记]4_字符串 ReplaceBlank
[剑指Offer笔记]4_字符串 ReplaceBlank题目描述:请实现一个函数,将字符串中的每个空格,替换成 “%20”分析:’ ’ 变成 “%20”: 一个字符变成3个字符,字符串长度会变长若从头开始遍历,移动的次数太多.选择从后面开始遍历.首先得统计需要移动次数,择可以得到最终字符串的长度.再用两个指针来表示出 原来字符串的末尾 和 新字符串的末尾....原创 2018-11-25 08:55:40 · 235 阅读 · 0 评论 -
[剑指Offer笔记] 06_树 reConstructBinaryTree
[剑指Offer笔记] 06_树 reConstructBinaryTree树除了根节点之外每个节点只有一个父节点根节点没有父节点除了叶节点之外所有节点都有一个或多个子节点叶节点没有子节点父节点与子节点用指针链接二叉树每个节点最多有两个子节点最重要的操作: 遍历遍历方式:前序遍历中序遍历后序遍历上述三种方法,都有递归和循环(非递归)的实现方...原创 2018-11-25 17:00:10 · 885 阅读 · 0 评论 -
[剑指Offer笔记]07 栈和队列 QueueWithTwoStacks
[剑指Offer笔记]07 栈和队列栈栈: 先进后出 / 后进先出一般不考虑排序: 需要O(n)时间找到最大/最小值队列队列: 先进先出 / 后进后出在按层次遍历树的时候需要用到!题目描述:用两个栈来实现一个队列,完成队列的Push和Pop操作。队列中的元素为int类型。分析:方法1:在push时做额外操作,就是将stack1压入stack2,node放入...原创 2018-11-25 17:47:10 · 173 阅读 · 0 评论 -
[剑指Offer笔记]08_查找与排序 minNumberInRotateArray
[剑指Offer笔记]08_查找与排序 minNumberInRotateArray面试重点注意:二叉查找归并排序快速排序注意: 很多算法有递归和循环两种写法. 递归代码简洁,但性能不如循环的.位运算! 是一种特殊的算法与 或 异或 左移 右移 这五种操作查找与排序顺序查找 / 二分查找 / 哈希表查找 / 二叉排序树查找对各类的排序算法都要烂熟于心,能够从...原创 2018-11-25 21:44:51 · 213 阅读 · 0 评论 -
[LeetCode]121. Best Time to Buy and Sell Stock 解题报告(C++)
[LeetCode]121. Best Time to Buy and Sell Stock 解题报告(C++)题目描述Say you have an array for which the i*th element is the price of a given stock on day *i.If you were only permitted to complete at m...原创 2018-08-03 10:20:48 · 329 阅读 · 0 评论 -
[LeetCode]122. Best Time to Buy and Sell Stock II 解题报告(C++)
[LeetCode]122. Best Time to Buy and Sell Stock II 解题报告(C++)题目描述Say you have an array for which the i*th element is the price of a given stock on day *i.Design an algorithm to find the maximum pr...原创 2018-08-03 10:21:51 · 431 阅读 · 0 评论 -
[LeetCode]217. Contains Duplicate 解题报告(C++)
[LeetCode]217. Contains Duplicate 解题报告(C++)题目描述Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the...原创 2018-08-03 10:22:28 · 257 阅读 · 0 评论 -
[LeetCode]268. Missing Number 解题报告(C++)
[LeetCode]268. Missing Number 解题报告(C++)题目描述Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.Example 1:Input: [3,0,1]Out...原创 2018-08-03 10:25:57 · 308 阅读 · 0 评论 -
[LeetCode]581. Shortest Unsorted Continuous Subarray 解题报告(C++)
[LeetCode]581. Shortest Unsorted Continuous Subarray 解题报告(C++)题目描述Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then th...原创 2018-08-03 09:56:41 · 222 阅读 · 0 评论 -
[LeetCode]717. 1-bit and 2-bit Characters 解题报告(C++)
[LeetCode]766. Toeplitz Matrix 解题报告(C++)题目描述A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.Now given an M x N matrix, return True if and only if the ...原创 2018-08-03 09:56:23 · 191 阅读 · 0 评论 -
[LeetCode]169. Majority Element 解题报告(C++)
[LeetCode]169. Majority Element 解题报告(C++)题目描述Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that t...原创 2018-08-02 14:52:56 · 337 阅读 · 0 评论 -
[LeetCode]448. Find All Numbers Disappeared in an Array 解题报告(C++)
[LeetCode]448. Find All Numbers Disappeared in an Array 解题报告(C++)题目描述Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find a...原创 2018-08-02 11:13:40 · 240 阅读 · 0 评论 -
[LeetCode]283. Move Zeroes 解题报告(C++)
[LeetCode]283. Move Zeroes 解题报告(C++)题目描述Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.Example:Input: ...原创 2018-08-02 10:58:10 · 151 阅读 · 0 评论 -
[LeetCode]695. Max Area of Island 解题报告(C++)
[LeetCode]695. Max Area of Island 解题报告(C++)题目描述Given a non-empty 2D array grid of 0’s and 1’s, an island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.)...原创 2018-08-02 10:50:03 · 276 阅读 · 0 评论 -
[LeetCode]167. Two Sum II - Input array is sorted 解题报告(C++)
[LeetCode]167. Two Sum II - Input array is sorted 解题报告(C++)题目描述Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target n...原创 2018-08-03 10:23:06 · 145 阅读 · 0 评论 -
[LeetCode]697. Degree of an Array 解题报告(C++)
[LeetCode]697. Degree of an Array 解题报告(C++)题目描述Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements.Yo...原创 2018-08-03 10:23:54 · 313 阅读 · 0 评论 -
[LeetCode]661. Image Smoother 解题报告(C++)
[LeetCode]661. Image Smoother 解题报告(C++)题目描述Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the aver...原创 2018-08-03 10:24:29 · 324 阅读 · 0 评论 -
[LeetCode]724. Find Pivot Index 解题报告(C++)
[LeetCode]724. Find Pivot Index 解题报告(C++)题目描述Given an array of integers nums, write a method that returns the “pivot” index of this array.We define the pivot index as the index where the sum of ...原创 2018-08-04 15:24:51 · 238 阅读 · 0 评论 -
[LeetCode]844. Backspace String Compare 解题报告(C++)
[LeetCode]844. Backspace String Compare 解题报告(C++)题目描述Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character.Example 1:...原创 2018-08-08 15:37:01 · 715 阅读 · 0 评论 -
[LeetCode]345. Reverse Vowels of a String 解题报告(C++)
[LeetCode]345. Reverse Vowels of a String 解题报告(C++)题目描述Write a function that takes a string as input and reverse only the vowels of a string.Example 1: Given s = “hello”, return “holle”.Exa...原创 2018-08-08 15:31:17 · 223 阅读 · 0 评论 -
[LeetCode]21. Merge Two Sorted Lists 解题报告(C++)
[LeetCode]21. Merge Two Sorted Lists 解题报告(C++)题目描述Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.E...原创 2018-08-07 22:28:56 · 249 阅读 · 0 评论 -
[LeetCode]203. Remove Linked List Elements 解题报告(C++)
[LeetCode]203. Remove Linked List Elements 解题报告(C++)题目描述Remove all elements from a linked list of integers that have value val.Example:Input: 1->2->6->3->4->5->6, val = ...原创 2018-08-07 22:27:49 · 228 阅读 · 0 评论 -
[LeetCode]234. Palindrome Linked List 解题报告(C++)
[LeetCode]234. Palindrome Linked List 解题报告(C++)题目描述Given a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2-&g...原创 2018-08-07 22:26:53 · 285 阅读 · 0 评论 -
[LeetCode]160. Intersection of Two Linked Lists 解题报告(C++)
[LeetCode]160. Intersection of Two Linked Lists 解题报告(C++)题目描述Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked ...原创 2018-08-07 22:26:26 · 176 阅读 · 0 评论 -
[LeetCode]141. Linked List Cycle 解题报告(C++)
[LeetCode]141. Linked List Cycle 解题报告(C++)题目描述Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?题目大意给一个单链表. 让你检查是否存在环.解题...原创 2018-08-07 22:26:00 · 269 阅读 · 0 评论 -
[LeetCode]830. Positions of Large Groups 解题报告(C++)
[LeetCode]830. Positions of Large Groups 解题报告(C++)题目描述In a string S of lowercase letters, these letters form consecutive groups of the same character.For example, a string like S = "abbxxxxzyy...原创 2018-08-03 10:25:29 · 223 阅读 · 0 评论 -
[LeetCode]485. Max Consecutive Ones 解题报告(C++)
[LeetCode]485. Max Consecutive Ones 解题报告(C++)题目描述Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The fir...原创 2018-08-02 10:12:15 · 186 阅读 · 0 评论 -
[LeetCode]566. Reshape the Matrix 解题报告(C++)
[LeetCode]566. Reshape the Matrix 解题报告(C++)题目描述In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original da...原创 2018-08-02 10:00:00 · 202 阅读 · 0 评论 -
[LeetCode]766. Toeplitz Matrix 解题报告(C++)
[LeetCode]766. Toeplitz Matrix 解题报告(C++)题目描述A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same element.Now given an M x N matrix, return True if and only if the ...原创 2018-08-02 09:48:49 · 342 阅读 · 0 评论 -
[LeetCode]219. Contains Duplicate II 解题报告(C++)
[LeetCode]219. Contains Duplicate II 解题报告(C++)题目描述Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] an...原创 2018-08-05 19:40:31 · 194 阅读 · 0 评论 -
[LeetCode]840. Magic Squares In Grid 解题报告(C++)
[LeetCode]840. Magic Squares In Grid 解题报告(C++)题目描述A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same s...原创 2018-08-05 19:40:01 · 449 阅读 · 0 评论 -
[LeetCode]26. Remove Duplicates from Sorted Array 解题报告(C++)
[LeetCode]26. Remove Duplicates from Sorted Array 解题报告(C++)题目描述Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not ...原创 2018-08-05 19:39:17 · 196 阅读 · 0 评论 -
[LeetCode]643. Maximum Average Subarray I 解题报告(C++)
[LeetCode]643. Maximum Average Subarray I 解题报告(C++)题目描述Given an array consisting of n integers, find the contiguous subarray of given length k that has the maximum average value. And you need to...原创 2018-08-05 19:37:58 · 223 阅读 · 0 评论 -
[LeetCode]849. Maximize Distance to Closest Person 解题报告(C++)
[LeetCode]849. Maximize Distance to Closest Person 解题报告(C++)题目描述In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty. There is at least one em...原创 2018-08-04 15:25:30 · 438 阅读 · 0 评论 -
[LeetCode]66. Plus One 解题报告(C++)
[LeetCode]66. Plus One 解题报告(C++)题目描述Given a non-empty array of digits representing a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is...原创 2018-08-04 15:23:55 · 459 阅读 · 0 评论