- 博客(41)
- 收藏
- 关注
原创 Leetcode 2926. Maximum Balanced Subsequence Sum
【代码】Leetcode 2926. Maximum Balanced Subsequence Sum。
2023-11-19 07:39:22
271
原创 Leetcode 2407. Longest Increasing Subsequence II
中的元素值的范围,对应value表示以该元素范围为结尾的最长递增子序列,那么在循环中我们只要查询。来存储以当前元素为结尾的最长递增子数列, 我们可以考虑对数组顺序循环,对每一个值。这样的时间复杂度相当于扫一遍长度为。为了解这个问题,我们可以构造一个线段树。的线段树进行查询和更新操作,总复杂度为。,其index可以表示。,每次对最大数值范围为。
2023-11-19 07:22:44
318
原创 leetcode#788. Rotated Digits
788. Rotated DigitsProblem Description X is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from X. Each digit must be rotated ...
2018-03-09 13:37:59
629
原创 leetcode#791. Custom Sort String
791. Custom Sort StringProblem Description S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sorted in some custom order previously. We want to...
2018-03-09 08:40:52
371
原创 leetcode#795. Number of Subarrays with Bounded Maximum
795. Number of Subarrays with Bounded MaximumProblem Description We are given an array A of positive integers, and two positive integers L and R (L <= R). Return the number of (contiguou...
2018-03-08 10:32:38
583
原创 leetcode#792. Number of Matching Subsequences
792. Number of Matching SubsequencesProblem Description Given string S and a dictionary of words words, find the number of words[i] that is a subsequence of S.Analysis and Solution基本思路是对wor...
2018-03-07 09:14:26
624
原创 leetcode#794. Valid Tic-Tac-Toe State
794. Valid Tic-Tac-Toe StateProblem Description A Tic-Tac-Toe board is given as a string array board. Return True if and only if it is possible to reach this board position during the course of ...
2018-03-06 10:46:16
525
原创 leetcode#793. Preimage Size of Factorial Zeroes Function
793. Preimage Size of Factorial Zeroes FunctionProblem Description Let f(x) be the number of zeroes at the end of x!. (Recall that x! = 1 * 2 * 3 * … * x, and by convention, 0! = 1.) For ...
2018-03-05 21:58:01
798
1
原创 leetcode#689. Maximum Sum of 3 Non-Overlapping Subarrays
689. Maximum Sum of 3 Non-Overlapping SubarraysProblem Description In a given array nums of positive integers, find three non-overlapping subarrays with maximum sum. Each subarray will be o...
2018-03-02 10:18:56
304
原创 leetcode#688. Knight Probability in Chessboard
688. Knight Probability in Chessboard题目描述 在NxN棋盘上,骑士从第r行和第c列开始,并尝试进行K次移动。 行和列都是0索引的,所以左上角的正方形是(0,0),右下角的正方形是(N-1,N-1)。 象棋骑士有8种可能的动作,如下图所示。 每个移动都是基本方向上的两个方格,然后是正交方向上的一个方格。 骑士每移动一次...
2018-03-01 09:26:32
463
原创 leetcode#789. Escape The Ghosts
789. Escape The GhostsProblem Description You are playing a simplified Pacman game. You start at the point (0, 0), and your destination is (target[0], target[1]). There are several ghosts on the...
2018-02-28 15:35:47
266
原创 leetcode#790. Domino and Tromino Tiling
790. Domino and Tromino TilingProblem Description We have two types of tiles: a 2x1 domino shape, and an “L” tromino shape. These shapes may be rotated. XX <- domino XX ...
2018-02-27 20:37:43
404
原创 leetcode#786. K-th Smallest Prime Fraction
786. K-th Smallest Prime FractionProblem Description A sorted list A contains 1, plus some number of primes. Then, for every p < q in the list, we consider the fraction p/q. What is the...
2018-02-25 14:14:33
574
原创 leetcode#780. Reaching Points
780. Reaching Points [hard]Problem Description: A move consists of taking a point (x, y) and transforming it to either (x, x+y) or (x+y, y). Given a starting point (sx, sy) and a target p...
2018-02-12 23:09:24
496
原创 leetcode#783. Minimum Distance Between BST Nodes
leetcode#783. Minimum Distance Between BST NodesProblem Description Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two differen...
2018-02-12 22:12:47
565
原创 leetcode# 669. Trim a Binary Search Tree
Problem Description Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the roo...
2018-02-11 21:24:47
251
原创 leetcode#773. Sliding Puzzle
leetcode#773. Sliding PuzzleProblem Description On a 2x3 board, there are 5 tiles represented by the integers 1 through 5, and an empty square represented by 0. A move consists of choosin...
2018-02-10 19:22:17
563
原创 leetcode#777. Swap Adjacent in LR String
leetcode#777. Swap Adjacent in LR StringProblem Description: In a string composed of ‘L’, ‘R’, and ‘X’ characters, like “RXXLRXRXL”, a move consists of either replacing one occurrence of “XL” wi...
2018-02-08 20:13:04
656
原创 leetcode#779 K-th Symbol in Grammar
EZ. 观察变换规律可知, 一个数字变换成的两个数字第一个还是他自己,另一个是他的反。所以把这n次操作看成完全二叉树,自底向上搜索即可。class Solution {public: int kthGrammar(int N, int K) { int flag = 0; while (N > 1) { flag = K % ...
2018-02-08 00:29:53
339
原创 leetcode#463 Island Perimeter
Description: You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid
2017-04-25 15:14:35
334
原创 leetcode#561 Array Partition I
Description: Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as l
2017-04-25 14:59:38
1210
原创 leetcode#563 Binary Tree Tilt
Description: Given a binary tree, return the tilt of the whole tree. The tilt of a tree node is defined as the absolute difference between the sum of all >left subtree node values and the sum of
2017-04-25 14:39:01
516
原创 leetcode#99 Recover Binary Search Tree
Description: Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure.Solution:这道题如果不考虑空间占用的话只要中序遍历找到乱序的两个数就可以了。但是题目中有说最好使用一个空间为O(1)的算法
2017-04-17 20:40:04
330
原创 leetcode#437 Path Sum III
Description: You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need to start or end at the root
2017-04-16 19:06:52
228
原创 leetcode#105 Construct Binary Tree from Preorder and Inorder Traversal
Desciption Given preorder and inorder traversal of a tree, construct the binary tree.这道题很简单,先序的第一个元素就是根元素,然后在中序中找到对应的位置,则左边的就是左子树,右边的即为右子树。值得注意的是,C++切片操作很难用,所以我就用Go写的解答。最后大部分debug时间都在解决语法问题T_TSoluti
2017-03-28 18:54:29
294
原创 leetcode#224 Basic Calculator
题目描述: Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or >minus sign -, non-negative integers
2017-03-23 15:35:31
389
原创 leetcode#94
Given a binary tree, return the inorder traversal of its nodes’ values. 给定一棵二叉树,返回它的中序遍历直接递归解决就可以了,没什么好说的。需要注意的是检查节点值是否为空。/** * Definition for a binary tree node. * struct TreeNode { * int v
2017-03-19 21:38:51
319
原创 leetcode#101 Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric But the following [1,2,2,null,3,null,3] i
2017-03-14 19:04:10
311
原创 leetcode#210 Course Schedule
题目: There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is >express
2016-10-16 14:06:36
334
原创 leetcode#77 Combinations
题目描述 Given two integers n and k, return all possible combinations of k numbers out of 1 … n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4],
2016-10-15 08:58:43
378
原创 leetcode#58 Length of Last Word
题目描述 Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the >length of last word in the string. If the last word does not exist, return 0. Note:
2016-10-14 18:32:38
263
原创 leetcode#321 Create Maximum Numbers
Given two arrays of length m and n with digits 0-9 representing two numbers. Create the >maximum number of length k <= m + n from digits of the two. The relative order of the digits >from the same arra
2016-10-13 19:14:52
416
原创 leetcode#15 Three Sum
这道题是Two Sum的升级版。本来想写一个三重循环暴力,结果超时了。后来我仔细想了想其实是用了STL的find函数所以超时的。 最后是用夹逼法写while循环做的:class Solution {public: vector<vector<int>> threeSum(vector<int>& nums) { vector<vector<int>> res;
2016-10-12 21:19:49
307
原创 leetcode#1 Two Sum
水题一个,直接用冒泡做了,但是很奇怪的是用vector<int> iterator和size_t的运行时间差了很多。前者直接就超时了,后者AC。class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { size_t n = nums.size(); vector<i
2016-10-12 12:40:39
368
原创 MySQL中的SELECT...INTO...FROM
MySQL不支持select…into…from语法,作为替代可以写成 CREATE NEW_TABLE ( SELECT column FROM old_table)好坑爹!!!
2016-05-16 21:01:47
545
原创 Neural Networks And Deep Learning(1)
文章系列是阅读Michael Nielsen的NNADL后做的一些笔记吧。 先挖个坑,有时间再填。
2016-05-07 19:00:50
358
原创 Arch环境的几款不错的软件
1、办公工具leafpad 以及libreoffice# pacman -S leafpad# pacman -S libreoffice 2、开发环境sublime text3以及eclipse# pacman -S sublime-text-dev# pacman -S eclipse3、笔记为知笔记,非常感人居然有linux客户端# pacman -S
2015-11-18 19:21:55
1205
原创 Archlinux初步系统安装
1.分盘# fdisk /dev/sdan创建新的分区,可以选择为p或者e,其实一直按enter就好了,记住分完盘以后一定要输入w来保存2.挂载# mkfs.ext4 /dev/sda1# mount /dev/sda1 /mnt先格式化以后再挂载3.安装# pacstrap -i /mnt base4.生成fstab# genfstab -U -p /mnt >>
2015-11-14 22:46:27
423
原创 快速排序
快排在python中可以这样实现:#!/usr/bin/env/ pythondef quickSort(aList): xs=[] smallerList=[] biggerList=[] if(len(aList)>1): xs.append(aList[0]) for i in range(1,len(aList)): if(aList[i]<=aList[0]):
2015-10-21 16:51:48
384
转载 x86-64和IA32的主要区别
1、指针和长整数是64位长。整数算术运算支持8、16、32和64位数据类型。2、通用目的寄存器组从8个拓展到16个3、许多程序状态都保存在寄存器中,而不是栈上。4、如果可能,条件操作用条件传送指令实现,会得到比传统分支代码更好的性能5、浮点操作用面向寄存器的指令集来实现,而不用IA32支持的基于栈的方法来实现
2015-10-15 11:09:37
3421
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人