随笔分类 -  Leetcode

486. 预测赢家(从递归到动态规划)
摘要:给定一个表示分数的非负整数数组。 玩家 1 从数组任意一端拿取一个分数,随后玩家 2 继续从剩余数组任意一端拿取分数,然后玩家 1 拿,…… 。每次一个玩家只能拿取一个分数,分数被拿取之后不再可取。直到没有剩余分数可取时游戏结束。最终获得分数总和最多的玩家获胜。 给定一个表示分数的数组,预测玩家1是 阅读全文

posted @ 2020-12-20 10:22 wsw_seu 阅读(155) 评论(0) 推荐(0) 编辑

210. 课程表 II(经典拓扑排序)
摘要:现在你总共有 n 门课需要选,记为 0 到 n-1。 在选修某些课程之前需要一些先修课程。 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们: [0,1] 给定课程总量以及它们的先决条件,返回你为了学完所有课程所安排的学习顺序。 可能会有多个正确的顺序,你只要返回一种就可以 阅读全文

posted @ 2020-12-16 21:17 wsw_seu 阅读(87) 评论(0) 推荐(0) 编辑

字典树(前缀树)
摘要:实现一个 Trie (前缀树),包含 insert, search, 和 startsWith 这三个操作。 示例: Trie trie = new Trie(); trie.insert("apple");trie.search("apple"); // 返回 truetrie.search("a 阅读全文

posted @ 2020-12-09 20:44 wsw_seu 阅读(103) 评论(0) 推荐(0) 编辑

旋转数组的最小数字
摘要:把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转。输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素。NOTE:给出的所有元素都大于0,若数组大小为0,请返回0。 class Solution { public: //3 4 5 1 2 int minNumberInRota 阅读全文

posted @ 2020-12-06 21:56 wsw_seu 阅读(72) 评论(0) 推荐(0) 编辑

215. Kth Largest Element in an Array(partition逆序排序,index+1 == k)
摘要:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Example 阅读全文

posted @ 2020-12-06 15:06 wsw_seu 阅读(126) 评论(0) 推荐(0) 编辑

220. Contains Duplicate III(核心:set数组有序/桶排序)
摘要:Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and 阅读全文

posted @ 2020-12-06 11:51 wsw_seu 阅读(85) 评论(0) 推荐(0) 编辑

leetcode 772 基本计算器III(包含+-*/ 以及括号) 核心在于递归
摘要:现基本计算器以计算简单表达式字符串。 表达式字符串可以包含左括号(和右括号)、加号+或减号、非负整数和空格。 表达式字符串只包含非负整数、+、-、*、/运算符、左括号和空格。整数除法应该截断为零。 您可以假定给定的表达式总是有效的。所有中间结果将在范围内[-2147483648,2147483647 阅读全文

posted @ 2020-12-02 20:22 wsw_seu 阅读(774) 评论(0) 推荐(0) 编辑

227. Basic Calculator II(重点记录上一个符号,每次判断上一个符号)
摘要:Given a string s which represents an expression, evaluate this expression and return its value. The integer division should truncate toward zero. Exam 阅读全文

posted @ 2020-12-02 20:06 wsw_seu 阅读(111) 评论(0) 推荐(0) 编辑

236. Lowest Common Ancestor of a Binary Tree
摘要:Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According to the definition of LCA on Wikipedia: “The lowes 阅读全文

posted @ 2020-11-29 17:39 wsw_seu 阅读(66) 评论(0) 推荐(0) 编辑

237. Delete Node in a Linked List
摘要:Write a function to delete a node in a singly-linked list. You will not be given access to the head of the list, instead you will be given access to t 阅读全文

posted @ 2020-11-29 16:43 wsw_seu 阅读(56) 评论(0) 推荐(0) 编辑

238. Product of Array Except Self
摘要:Given an array nums of n integers where n > 1, return an array output such that output[i] is equal to the product of all the elements of nums except n 阅读全文

posted @ 2020-11-29 16:25 wsw_seu 阅读(42) 评论(0) 推荐(0) 编辑

单调队列 Monotonic Queue应用:leetcode(未完待续)
摘要:239. Sliding Window Maximum 581: https://leetcode.com/problems/shortest-unsorted-continuous-subarray/ 862: https://leetcode.com/problems/shortest-suba 阅读全文

posted @ 2020-11-22 15:32 wsw_seu 阅读(153) 评论(0) 推荐(0) 编辑

240. Search a 2D Matrix II
摘要:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted i 阅读全文

posted @ 2020-11-22 10:23 wsw_seu 阅读(173) 评论(0) 推荐(0) 编辑

279. Perfect Squares(dp)
摘要:Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n. Example 1: Input: n = 12 O 阅读全文

posted @ 2020-11-21 22:18 wsw_seu 阅读(106) 评论(0) 推荐(0) 编辑

283. Move Zeroes(双指针)
摘要: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: 阅读全文

posted @ 2020-11-18 23:17 wsw_seu 阅读(59) 评论(0) 推荐(0) 编辑

287. Find the Duplicate Number
摘要:Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one duplicate number in n 阅读全文

posted @ 2020-11-18 23:15 wsw_seu 阅读(108) 评论(0) 推荐(0) 编辑

289. Game of Life
摘要:According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John 阅读全文

posted @ 2020-11-15 13:22 wsw_seu 阅读(106) 评论(0) 推荐(0) 编辑

128. 最长连续序列
摘要:给定一个未排序的整数数组,找出最长连续序列的长度。 要求算法的时间复杂度为 O(n)。 示例: 输入: [100, 4, 200, 1, 3, 2]输出: 4解释: 最长连续序列是 [1, 2, 3, 4]。它的长度为 4。 0 1 1 2 输出 3 class Solution { public: 阅读全文

posted @ 2020-07-07 10:01 wsw_seu 阅读(121) 评论(0) 推荐(0) 编辑

665. Non-decreasing Array
摘要:Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1element. We define an array is non-decre 阅读全文

posted @ 2019-03-24 10:51 wsw_seu 阅读(124) 评论(0) 推荐(0) 编辑

227. Basic Calculator II
摘要:Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +, -, *, / operators a 阅读全文

posted @ 2018-02-02 10:17 wsw_seu 阅读(113) 评论(0) 推荐(0) 编辑

导航

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示