加载中...

daily leetcode - scramble-string - !

题目地址 https://leetcode.com/problems/scramble-string/ 题目描述 Given a string s1 , we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representation of s1 = "great": great / \ gr eat / \ / \ g r e at / \ a t To scramble the string, we may choose any non-leaf node and swap its two children. For example, if we choose the node "gr" and swap its two children, it produces a scrambled string "rgeat". rgeat / \ rg eat / \ / \ r g e at / \....

daily leetcode - partition-list - !

题目地址 https://leetcode.com/problems/partition-list/ 题目描述 Given a linked list and a value x , partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two partitions. For example, Given 1->4->3->2->5->2 and x = 3, return 1->2->2->4->3->5. 思路 这道题要求我们划分链表,把所有小于给定值的节点都移到前面,大于该值的节点顺序不变,相当于一个局部排序的问题。那么可以想到的一种解法是首先找到第一个大于或等于给定值的节点,用题目中给的例子来说就是先找到 4,然后再找小于 3 的值,每找到一个....

数学公式--修正版(mathjax显示语法错误)

高等数学 1.导数定义: 导数和微分的概念 $f'(x_{0}) = \lim_{\Delta x \rightarrow 0},\frac{f(x_{0} + \Delta x) - f(x_{0})}{\text{Δx}}$ (1) 或者:$f'(x_{0}) = \lim_{x \rightarrow x_{0}},\frac{f(x) - f(x_{0})}{x - x_{0}}$ (2) 2.左右导数导数的几何意义和物理意义 函数$f(x)$在$x_{0}$处的左、右导数分别定义为: 左导数:${f'}{-}(x{0}) = \lim_{\Delta x \rightarrow 0^{-}},\frac{f(x_{0} + \Delta x) - f(x_{0})}{\text{Δx}} = \lim_{x \rightarrow x_{0}^{-}},\frac{f(x) - f(x_{0})}{x - x_{0}},(x = x_{0} + \Delta x)$ 右导数:${f'}{+}(x{0}) = \lim_{\Delta x \rightarrow 0^{+}}....

daily leetcode - maximal-rectangle - !

题目地址 https://leetcode.com/problems/maximal-rectangle/ 题目描述 Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1's and return its area. Example: Input: [ ["1","0","1","0","0"], ["1","0","1","1","1"], ["1","1","1","1","1"], ["1","0","0","1","0"] ] Output: 6 思路 此题是之前那道的 Largest Rectangle in Histogram 的扩展,这道题的二维矩阵每一层向上都可以看做一个直方图,输入矩阵有多少行,就可以形成多少个直方图,对每个直方图都调用 Largest Rectangle in Histogram 中的方法,就可以得到最大的矩形面积。那么这道题唯一要做的就是将每一层都当作直方图的底层,并向上构造整个直方图,由于题目限定了输入矩阵的字....

daily leetcode - largest-rectangle-in-histogram - !

题目地址 https://leetcode.com/problems/largest-rectangle-in-histogram/ 题目描述 Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width of each bar is 1, given height = [2,1,5,6,2,3]. The largest rectangle is shown in the shaded area, which has area = 10 unit. For example, Given height = [2,1,5,6,2,3], return 10. 思路 这道题让求直方图中最大的矩形,刚开始看到求极值问题以为要用 DP 来做,可是想不出递推式,只得作罢。这道题....

daily leetcode - remove-duplicates-from-sorted-list - !

题目地址 https://leetcode.com/problems/remove-duplicates-from-sorted-list/ 题目描述 Given a sorted linked list, delete all duplicates such that each element appear only once. Example 1: Input: 1->1->2 Output: 1->2 Example 2: Input: 1->1->2->3->3 Output: 1->2->3 思路 这道题让我们移除给定有序链表的重复项,那么可以遍历这个链表,每个结点和其后面的结点比较,如果结点值相同了,只要将前面结点的 next 指针跳过紧挨着的相同值的结点,指向后面一个结点。这样遍历下来,所有重复的结点都会被跳过,留下的链表就是没有重复项的了。 关键点解析 代码 解法一: class Solution { public: ListNode* deleteDuplicates(ListNode* head) { Lis....

daily leetcode - remove-duplicates-from-sorted-list-ii - !

题目地址 https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ 题目描述 Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Example 1: Input: 1->2->3->3->4->4->5 Output: 1->2->5 Example 2: Input: 1->1->1->2->3 Output: 2->3 思路 和之前那道 Remove Duplicates from Sorted List 不同的地方是这里要删掉所有的重复项,由于链表开头可能会有重复项,被删掉的话头指针会改变,而最终却还需要返回链表的头指针。所以需要定义一个新的节点,然后链上原链表,然后定义一个前驱指针和一个现指针,每当前驱指针指向新建的....

daily leetcode - search-in-rotated-sorted-array-ii - !

题目地址 https://leetcode.com/problems/search-in-rotated-sorted-array-ii/ 题目描述 Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., [0,0,1,2,2,5,6] might become [2,5,6,0,0,1,2]). You are given a target value to search. If found in the array return true, otherwise return false. Example 1: Input: nums = [2,5,6,0,0,1,2], target = 0 Output: true Example 2: Input: nums = [2,5,6,0,0,1,2], target = 3 Output: false Follow up: This is a follow up problem to....

随笔 2020-2-28

🔥 随便记点什么吧! 今天是 2020 年 2 月 28 日,距离我当初为期六个月攒钱的计划已经过去了一半,钱是没攒到多少,倒是攒下了工作中满满的不如意。在网上买的高数 36 今天中午到了,久违的高数啊,今天晚上吃过晚饭,洗好碗后,就迫不及待的拆开包装,打开一看懵了,那些曾经非常熟悉,了然于心,背的滚瓜烂熟的数学公式在时隔一年多之后的今天竟然忘得一塌糊涂,惭愧呀!🐧 幸好当初离开学校的时候,把专业课、高数等这些硬书给寄了回来。回望一下基础,应当会加深对以往知识的理解。刚刚看了两节,果然还是当初熟悉的味道,还是那么的一看就明白,做题就是不会的感觉!😄 🚧 今天在这里定下一个小小的目标,在 4 月份之前,争取看完高数的 18 讲。

daily leetcode - remove-duplicates-from-sorted-array-ii - !

题目地址 https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/ 题目描述 Given a sorted array nums , remove the duplicates in-place such that duplicates appeared at most twice and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Example 1: Given _nums_ = [1,1,1,2,2,3], Your function should return length = 5, with the first five elements of _nums_ being 1, 1, 2, 2 and 3 respectively. It does....

avatar
Lonus Lan
It's better to burn out than to fade away!
公告
暂无更新通知!
最新文章
网站资讯
文章数目 :
156
已运行时间 :
0 天
本站在线访客数 :
1
本站总访问量 :
0