跳过正文
  1. Tags/

Leetcode

2021

2020年终总结

·1280 字·3 分钟
本来不知道写什么所以不打算写了,不过后来觉得可以把今年做的一些重大的决定写出来,把当时的分析和想法记录下来。这样若干年后再回看,就能找到:是哪些明智或愚蠢的决定对人生产生了巨大的影响。

2017

leetcode 146. LRU Cache(list+unordered_map)

·457 字·1 分钟
请实现最近最少使用缓存(Least Recently Used (LRU) cache)类,需要支持 get, set,操作。 get 操作,给出 key,获取到相应的 value (value 为非负数),如果不存在返回-1, 如果存在此 key 算作被访问过。 set 操作,设置 key,如果 key 存在则覆盖之前的 value (此时相当于访问过一次)。 如果 key 不存在,需要进行插入操作,如果此时已经 key 的数量已经到达 capacity, 这样需要淘汰掉最近最少使用(也就是上次被使用的时间距离现在最久的)的那 一项。

leetcode 228. Summary Ranges

·412 字·1 分钟
Given a sorted integer array without duplicates, return the summary of its ranges. For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"]. 题意:把连续的数连续表示

leetcode 75. Sort Colors

·628 字·2 分钟
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.

leetcode 11. Container With Most Water (two pointer)

·328 字·1 分钟
Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.