自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Codeless Code Case1 Small Stuff

Codeless Code的译文和我对文章的理解

2023-02-25 12:07:28 346

原创 1109. Corporate Flight Bookings

There are n flights, and they are labeled from 1 to n.We have a list of flight bookings. The i-th booking bookings[i] = [i, j, k] means that we booked k seats from flights labeled i to j inclusive....

2019-10-05 07:25:52 392

原创 787. Cheapest Flights Within K Stops

There are n cities connected by m flights. Each fight starts from city u and arrives at v with a price w.Now given all the cities and flights, together with starting city src and the destination dst,...

2019-10-05 07:10:44 227

原创 KMP算法:两个字符串的匹配,S1里匹配S2

通过创建一个部分匹配表来优化指针后移的效率。http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html

2019-10-04 02:18:29 314

原创 647. Palindromic Substrings(java)

Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist o...

2019-10-03 06:55:10 150

原创 685. Redundant Connection II(java)

In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, excep...

2019-10-03 05:37:16 123

原创 684. Redundant Connection(java)

In this problem, a tree is an undirected graph that is connected and has no cycles.The given input is a graph that started as a tree with N nodes (with distinct values 1, 2, …, N), with one additiona...

2019-10-03 02:15:51 233

原创 355. Design Twitter

Design a simplified version of Twitter where users can post tweets, follow/unfollow another user and is able to see the 10 most recent tweets in the user’s news feed. Your design should support the fo...

2019-09-26 08:41:17 80

转载 约瑟夫环

约瑟夫问题约瑟夫问题是个著名的问题:N个人围成一圈,第一个人从1开始报数,报M的将被杀掉,下一个人接着从1开始报。如此反复,最后剩下一个,求最后的胜利者。例如只有三个人,把他们叫做A、B、C,他们围成一圈,从A开始报数,假设报2的人被杀掉。首先A开始报数,他报1。侥幸逃过一劫。然后轮到B报数,他报2。非常惨,他被杀了C接着从1开始报数接着轮到A报数,他报2。也被杀死了。最终胜利者是C...

2019-09-26 05:34:18 172

原创 390. Elimination Game(约瑟夫环)

There is a list of sorted integers from 1 to n. Starting from left to right, remove the first number and every other number afterward until you reach the end of the list.Repeat the previous step agai...

2019-09-26 05:31:02 93

原创 60. Permutation Sequence

The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order, we get the following sequence for n = 3:“123”“132”“213”“231”“312”“321”G...

2019-09-25 11:23:17 70

原创 381. Insert Delete GetRandom O(1) - Duplicates allowed

Design a data structure that supports all following operations in average O(1) time.Note: Duplicate elements are allowed.insert(val): Inserts an item val to the collection.remove(val): Removes an i...

2019-09-25 05:14:02 145

原创 23. Merge k Sorted Lists

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3->4-&g...

2019-09-25 02:32:09 70

原创 146. LRU Cache

Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key if the...

2019-09-24 15:20:02 75

原创 380. Insert Delete GetRandom O(1)

Design a data structure that supports all following operations in average O(1) time.insert(val): Inserts an item val to the set if not already present.remove(val): Removes an item val from the set i...

2019-09-24 14:02:43 78

原创 432. All O`one Data Structure(java)

Implement a data structure supporting the following operations:Inc(Key) - Inserts a new key with value 1. Or increments an existing key by 1. Key is guaranteed to be a non-empty string.Dec(Key) - If...

2019-09-24 12:55:12 307

原创 二进制作为hashset存放visited,获取和设置第n位的值

获取x第n位的值:(x>>n) & 1设置x第n位的值为1:x = x || 1<<n

2019-09-10 13:03:18 100

原创 53. Maximum Subarray(写1186顺便复习一下这道题的两种写法)

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanation...

2019-09-09 13:39:02 132

原创 LeetCode 1186. Maximum Subarray Sum with One Deletion(java)

Given an array of integers, return the maximum sum for a non-empty subarray (contiguous elements) with at most one element deletion. In other words, you want to choose a subarray and optionally delete...

2019-09-09 13:35:57 562

原创 LeetCode 815. Bus Routes(java)

We have a list of bus routes. Each routes[i] is a bus route that the i-th bus repeats forever. For example if routes[0] = [1, 5, 7], this means that the first bus (0-th indexed) travels in the sequenc...

2019-09-09 09:34:47 428

原创 LeetCode 743. Network Delay Time(Dijistra算法)

There are N network nodes, labelled 1 to N.Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the target node, and w is the time it takes for...

2019-09-08 14:48:32 247

转载 给年,月,日,求星期几,基姆拉尔森(kim larson)计算公式

设定int y; //年int m; //月int d; //日int w; //周几从 公元0年1月1日星期日 开始推导对于第一个月w = (d-1) % 7 --------- 公式(1)对于年不考虑闰年在不考虑闰年的情况下,一年365天,365%7=1,就是说一年的第一天和最后一天是相同的。等价于,下一年的第一天星期几是会比这一年的最后一天+1的。完善公式...

2019-09-08 13:11:32 208

原创 630. Course Schedule III(java)

There are n different online courses numbered from 1 to n. Each course has some duration(course length) t and closed on dth day. A course should be taken continuously for t days and must be finished b...

2019-09-04 13:19:14 107

原创 1157. Online Majority Element In Subarray

Implementing the class MajorityChecker, which has the following API:MajorityChecker(int[] arr) constructs an instance of MajorityChecker with the given array arr;int query(int left, int right, int t...

2019-08-26 15:03:15 545

原创 407. Trapping Rain Water II

Given an m x n matrix of positive integers representing the height of each unit cell in a 2D elevation map, compute the volume of water it is able to trap after raining.Note:Both m and n are less th...

2019-08-25 02:06:15 135

原创 LeetCode 34. Find First and Last Position of Element in Sorted Array(java) -- binary search template

Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If the t...

2019-08-22 11:06:17 128

原创 LeetCode 1163. Last Substring in Lexicographical Order(java)

Given a string s, return the last substring of s in lexicographical order.Example 1:Input: "abab"Output: "bab"Explanation: The substrings are ["a", "ab", "aba", "abab", "b", "ba", "bab"]. The lex...

2019-08-21 12:12:24 1110

原创 LeetCode 726. Number of Atoms(java)

Given a chemical formula (given as a string), return the count of each atom.An atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name.1 ...

2019-08-21 11:33:20 370

原创 LeetCode 736 Parse Lisp Expression

You are given a string expression representing a Lisp-like expression to return the integer value of.The syntax for these expressions is given as follows.An expression is either an integer, a let-ex...

2019-08-20 12:53:12 154

原创 LeetCode 862. Shortest Subarray with Sum at Least K(单调队列)

Return the length of the shortest, non-empty, contiguous subarray of A with sum at least K.If there is no non-empty subarray with sum at least K, return -1.Example 1:Input: A = [1], K = 1Output: 1...

2019-08-14 12:39:11 163

原创 单调栈和单调队列

单调栈是指栈内元素维持单调递增或者单调递减的栈。多用于求数组一边的性质,因为栈是只能一边操作的,例如:求数组里距离此元素最近的大于此元素的值(递减栈,因为栈里存放的都可能完成任务的值),或者是,距离此元素最近的小于此元素的值(递增栈)。单调队列是维护一个单调递增或者单调递减的队列,例如一个的deque,两边都可以操作。单调队列用于求距离此元素值相差在多少范围内的最近的元素值。因为相比较栈多了一个...

2019-08-14 12:16:45 119

原创 5. Longest Palindromic Substring(java)

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answer.Exampl...

2019-07-11 13:06:24 239

原创 729. My Calendar I (java)

Implement a MyCalendar class to store your events. A new event can be added if adding the event will not cause a double booking.Your class will have the method, book(int start, int end). Formally, th...

2019-07-11 12:42:27 202

原创 LeetCode 1024. Video Stitching(java)

You are given a series of video clips from a sporting event that lasted T seconds. These video clips can be overlapping with each other and have varied lengths.Each video clip clips[i] is an interva...

2019-07-10 15:17:27 182

原创 LeetCode 871. Minimum Number of Refueling Stops(java)

A car travels from a starting position to a destination which is target miles east of the starting position.Along the way, there are gas stations. Each station[i] represents a gas station that is st...

2019-07-10 14:41:30 255

原创 LeetCode 1040. Moving Stones Until Consecutive II(java)

On an infinite number line, the position of the i-th stone is given by stones[i]. Call a stone an endpoint stone if it has the smallest or largest position.Each turn, you pick up an endpoint stone a...

2019-07-08 05:47:46 611

原创 LeetCode 1111. Maximum Nesting Depth of Two Valid Parentheses Strings(java)

A string is a valid parentheses string (denoted VPS) if and only if it consists of “(” and “)” characters only, and:It is the empty string, orIt can be written as AB (A concatenated with B), where A...

2019-07-08 03:18:56 461

原创 LeetCode 1110. Delete Nodes And Return Forest(java)

Given the root of a binary tree, each node in the tree has a distinct value.After deleting all nodes with a value in to_delete, we are left with a forest (a disjoint union of trees).Return the roots...

2019-07-08 03:16:08 490

原创 LeetCode1033. Moving Stones Until Consecutive(java)

Three stones are on a number line at positions a, b, and c.Each turn, you pick up a stone at an endpoint (ie., either the lowest or highest position stone), and move it to an unoccupied position betw...

2019-07-08 03:11:26 221

原创 LeetCode 963. Minimum Area Rectangle II(java)

Given a set of points in the xy-plane, determine the minimum area of any rectangle formed from these points, with sides not necessarily parallel to the x and y axes.If there isn’t any rectangle, retu...

2019-07-06 06:34:35 164

空空如也

空空如也

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

TA关注的人

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