自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(51)
  • 收藏
  • 关注

原创 Leetcode 142 Linked List Cycle II

Leetcode 142 Linked List Cycle II题目思路代码题目Given a linked list, return the node where the cycle begins. If there is no cycle, return null.There is a cycle in a linked list if there is some node in the list that can be reached again by continuously followi

2020-10-27 20:02:50 281

原创 Leetcode 799 champagne tower

Leetcode 799 champagne tower题目思路代码题目We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100th row. Each glass holds one cup (250ml) of champagne.Then, some champagne is poured in the first g

2020-10-26 17:44:39 300

原创 Leetcode 1510 Stone Game IV

Leetcode 1510 Stone Game IV题目思路代码优化题目Alice and Bob take turns playing a game, with Alice starting first.Initially, there are n stones in a pile. On each player’s turn, that player makes a move consisting of removing any non-zero square number of stones

2020-10-26 16:51:22 241

原创 Leetcode 1007 Minimum Domino Rotations For Equal Row

Leetcode 1007 Minimum Domino Rotations For Equal Row题目思路代码题目In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the ith domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)We may rotate the it

2020-10-19 15:34:43 311

原创 Leetcode 187 Repeated DNA Sequences

Leetcode 187 Repeated DNA Sequences题目思路代码优化题目All DNA is composed of a series of nucleotides abbreviated as ‘A’, ‘C’, ‘G’, and ‘T’, for example: “ACGAATTCCG”. When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Write a

2020-10-17 17:27:32 101

原创 Leetcode 74 Search a 2D Matrix

Leetcode 74 Search a 2D Matrix题目思路代码题目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 from left to right.The first integer of each row is greater than t

2020-10-16 20:53:53 93

原创 Leetcode 189 Rotate Array

Leetcode 189 Rotate Array题目思路代码题目Given an array, rotate the array to the right by k steps, where k is non-negative.Follow up:Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.Could you do it in-plac

2020-10-15 21:53:08 136

原创 Leetcode 213 House Robber II

Leetcode 213 House Robber II题目思路代码题目You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of th

2020-10-14 18:27:48 135

原创 Leetcode 148 Sort List

Leetcode 148 Sort List题目思路代码题目Given the head of a linked list, return the list after sorting it in ascending order.Follow up: Can you sort the linked list in O(n logn) time and O(1) memory (i.e. constant space)?Example 1:Input: head = [4,2,1,3]Outpu

2020-10-13 20:26:24 93

原创 Leetcode 859 Buddy Strings

Leetcode 859 Buddy Strings题目思路代码题目Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to B, otherwise, return false.Swapping letters is defined as taking two indices i and j (0-indexed) suc

2020-10-13 07:38:31 106

原创 Leetcode 316 Remove Duplicate Letters

Leetcode 316 Remove Duplicate Letters题目代码题目Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.Note: This question

2020-10-11 22:05:01 104

原创 Leetcode 452 Minimum Number of Arrows to Burst Balloons

Leetcode 452 Minimum Number of Arrows to Burst Balloons题目思路和代码题目There are some spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it’s horizontal, y-coor

2020-10-10 21:50:05 95

原创 Leetcode 449 Serialize and Deserialize BST

Leetcode 449 Serialize and Deserialize BST题目思路代码优化题目Serialization is converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed la

2020-10-10 07:41:33 192

原创 Leetcode 704 Binary Search

题目Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If target exists, then return its index, otherwise return -1.Example 1:Input: nums = [-1,0,3,5,9,12], target = 9Outpu

2020-10-08 18:16:06 89

原创 Leetcode 61 Rotate List

Leetcode 61 Rotate List题目思路代码题目Given a linked list, rotate the list to the right by k places, where k is non-negative.Example 1:Input: 1->2->3->4->5->NULL, k = 2Output: 4->5->1->2->3->NULLExplanation:rotate 1 steps to

2020-10-07 20:15:39 112

原创 Leetcode 701 Insert into a Binary Search Tree

Leetcode 701 Insert into a Binary Search Tree题目代码题目You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in t

2020-10-06 17:01:18 199 2

原创 Leetcode 1009 Complement of Base 10 Integer

Leetcode 1009 Complement of Base 10 Integer题目思路题目Every non-negative integer N has a binary representation. For example, 5 can be represented as “101” in binary, 11 as “1011” in binary, and so on. Note that except for N = 0, there are no leading zeroes

2020-10-06 12:36:00 160

原创 Leetcode 1288 Remove Covered Intervals

Leetcode 1288 Remove Covered Intervals题目思路题目Given a list of intervals, remove all intervals that are covered by another interval in the list.Interval [a,b) is covered by interval [c,d) if and only if c <= a and b <= d.After doing so, return the n

2020-10-04 20:21:08 106

原创 LeetCode 532 K-diff Pairs in an Array

LeetCode 532 K-diff Pairs in an Array题目思路代码题目Given an array of integers nums and an integer k, return the number of unique k-diff pairs in the array.A k-diff pair is an integer pair (nums[i], nums[j]), where the following are true:0 <= i, j < num

2020-10-03 19:34:07 71

原创 Leetcode 39 Combination Sum

Leetcode 39 Combination Sum题目思路代码题目Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order.Th

2020-10-02 15:33:41 176

原创 Leetcode 933 RecentCounter

题目You have a RecentCounter class which counts the number of recent requests within a certain time frame.Implement the RecentCounter class:RecentCounter() Initializes the counter with zero recent requests.int ping(int t) Adds a new request at time t, wh

2020-10-02 08:16:51 155

原创 Leetcode 41 First Missing Positive

Leetcode 41 First Missing Positive题目思路代码题目Given an unsorted integer array, find the smallest missing positive integer.Example 1:Input: [1,2,0]Output: 3Example 2:Input: [3,4,-1,1]Output: 2Example 3:Input: [7,8,9,11,12]Output: 1Follow up:Y

2020-09-30 16:32:00 131

原创 Leetcode 139 Word Break

题目Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.Note:The same word in the dictionary may be reused multiple time

2020-09-29 16:27:40 103

原创 最短路(三) A star Heuristics

A star属于一种best-first search,通过不断选择当前预期距离最小的点来实现。参考:http://www.cs.cmu.edu/~cga/ai-course/astar.pdfhttps://en.wikipedia.org/wiki/A*_search_algorithm标记g(n)=distance[start][n]g(n) = distance[start][n]g(n)=distance[start][n], (当前计算得到的准确值)h(n)=distance[n]

2020-09-29 14:08:51 331

原创 最短路(二) All Pairs

最短路(二) All PairsFloyd Warshall AlgorithmJohnson's Algorithm与单起点的问题不同,这类问题需要同时求解出该图中任意两点间的最短路径。Floyd Warshall Algorithm动态规划的想法,记录P为从点i到点j满足路上所有点都在VkV^kVk中的最短路,与在Vk−1V^{k-1}Vk−1上的子问题相比有两种可能,点k不在P上,此时最短路为Vk−1V^{k-1}Vk−1中的最短路点k在P上,此时最短路为i到k的最短路加上k到j的最短路

2020-09-29 14:03:54 356

原创 最短路(一)Single Source

最短路(一) 单起点DijkstraBellman-Ford Algorithm在一个图中,给定起点,求到别的点的最短路。Dijkstra创建一个距离数组,记录当前起点到该点的最短距离,起点距离初始化为0,其余点初始化为正无穷。创建最小堆pq,用来存放当前已经找到最小距离的点,初始化为起点,比较原则是根据当前的最小距离。当堆内仍有元素为处理完时:- 取出当前距离最小的未访问的点- 更新它的neighbor的通过该点的距离(如果比原来记录的小的话)并将其加入堆中正确性:假设当前距离最小的点VV

2020-09-28 20:57:52 509

原创 Leetcode 713 Subarray Product Less Than K

Leetcode 713 Subarray Product Less Than K题目思路代码题目Your are given an array of positive integers nums.Count and print the number of (contiguous) subarrays where the product of all the elements in the subarray is less than k.Example 1:Input: nums = [10,

2020-09-28 16:24:30 87

原创 Greedy Algorithm 贪心算法

Greedy Algorithm 贪心算法Job Schedule ProblemMST Prim's AlgorithmMax-Spacing k clusteringHuffman CodeGreedy Heuristic for Knapsack Problem贪心算法总是选择当前最优的选择,有的时候并不保证正确,以下给出五个例子,前四个为准确算法,最后一个为Heuristic。Job Schedule Problem有一组任务,权重是wiw_{i}wi​,完成需要的时长为lil_{i}li​,

2020-09-28 14:26:54 492

原创 Divide And Conquer 分治法

Divide And Conquer算法的实质就是把大问题分解成小问题,然后依次解决,最经典的例子是mergeSort,通过不断分别排序左右两个子列后连接。用于计算分治法问题Runtime的定理:Master Theorem如果有T(n)≤aT(nb)+cndT(n) \le a T(\frac{n}{b}) + cn^dT(n)≤aT(bn​)+cnd,其中aaa为子问题个数,bbb决定子问题大小,cndcn^dcnd连接各子问题需要的时间,有如下Runtime={O(ndlog(n)),a=bd

2020-09-27 21:45:53 169

原创 Leetcode 399 Evaluate Division

Leetcode 399 Evaluate Division题目思路代码题目You are given equations in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating-point number). Given some queries, return the answers. If the answer does not exis

2020-09-27 16:17:29 135

原创 Leetcode 495 Teemo Attacking

Leetcode 495 Teemo Attacking题目思路代码题目In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo’s attacking ascending time series towards Ashe and the poisoning time duration per Tee

2020-09-26 18:04:53 129

原创 Leetcode 179 Largest Number

Leetcode 179 Largest Number题目思路代码优化题目Given a list of non negative integers, arrange them such that they form the largest number.Example 1:Input: [10,2]Output: “210”Example 2:Input: [3,30,34,5,9]Output: “9534330”Note: The result may be very larg

2020-09-25 21:57:23 169

原创 Leetcode 389 Find the Difference

Leetcode 389 Find the Difference题目思路和代码题目Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was added in t.Exampl

2020-09-24 21:05:46 154

原创 Leetcode 134 Gas Station

Leetcode 134 Gas Station题目思路代码题目There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its next station (i+1). You

2020-09-23 16:09:57 152

原创 Leetcode 229 Majority Element II

Leetcode 229 Majority Element II题目思路题目Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times.Note: The algorithm should run in linear time and in O(1) space.Example 1:Input: [3,2,3]Output: [3]Example 2:Input: [1,

2020-09-22 17:08:26 131

原创 Java 3 多线程

Java3 多线程资料来源:《Java程序设计基础(第六版)》Java支持多线程,使各代码段并发执行。Q:并发和并行的区别A:并行是指同一时刻有多个代码在处理器上执行,需硬件支持;并发执行是在单处理器上,同一时刻只能执行一个代码,但同一时段内代码段交替执行,实现“微观串行,宏观并行”。基本概念:程序(program):静态的代码进程(process):一个运行中的程序。进程是操作系统资源分配和处理器调度的基本单元。线程(thread):包含在进程内,同类的多个线程共享内存空间和系统资源线程

2020-09-21 21:19:16 193

原创 Leetcode 1094 Car Pooling

Leetcode 1094 Car Pooling题目代码题目You are driving a vehicle that has capacity empty seats initially available for passengers. The vehicle only drives east (ie. it cannot turn around and drive west.)Given a list of trips, trip[i] = [num_passengers, start_l

2020-09-21 21:18:39 164

原创 Leetcode 980 Unique Paths III

Leetcode 980 Unique Paths III题目思路代码优化题目On a 2-dimensional grid, there are 4 types of squares:1 represents the starting square. There is exactly one starting square.2 represents the ending square. There is exactly one ending square.0 represents empty

2020-09-20 17:18:17 138

原创 Leetcode 1291 Sequential Digits

Leetcode 1291 Sequential Digits题目思路代码题目An integer has sequential digits if and only if each digit in the number is one more than the previous digit.Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.

2020-09-19 20:40:30 124

原创 Java2 IO处理

Java2 IO处理Java使用流来处理数据的输入输出,主要借助于包java.io来实现,流是指计算机各部件之间的数据流动。分类:按数据传输方向:输入流和输出流按内容:字节流和字符流Q:为什么采用数据流处理输入输出?A:使程序的输入输出操作独立于相关设备,每个设备的实现细节由系统完成,源代码不需要做修改,增加可移植性输入输出流字节流(一次读8位):InputStream, OutputStream常用于读写图片、音频、视频等二进制数据字符流(一次读16位):Reader,Writer一

2020-09-19 20:35:10 84

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除