JinFei's Blog

Thinking will not overcome fear but action will.

[LeetCode]328. 奇偶链表

奇偶链表

题目描述 给定一个单链表,把所有的奇数节点和偶数节点分别排在一起。请注意,这里的奇数节点和偶数节点指的是节点编号的奇偶性,而不是节点的值的奇偶性。 请尝试使用原地算法完成。你的算法的空间复杂度应为 O(1),时间复杂度应为 O(nodes),nodes 为节点总数。 Example1: 输入: 1->2->3->4->5->NULL 输出: 1...

[LeetCode]剑指 Offer II 010. 和为 k 的子数组

和为 k 的子数组

题目描述 给定一个整数数组和一个整数 k ,请找到该数组中和为 k 的连续子数组的个数。 Example1: 输入:nums = [1,1,1], k = 2 输出: 2 解释: 此题 [1,1] 与 [1,1] 为两种不同的情况 Example2: 输入:nums = [1,2,3], k = 3 输出: 2 Note: 1 <= nums.len...

[LeetCode]剑指 Offer II 009. 乘积小于 K 的子数组

小于 K 的子数组

题目描述 给定一个正整数数组 nums和整数 k ,请找出该数组内乘积小于 k 的连续的子数组的个数。 Example1: 输入: nums = [10,5,2,6], k = 100 输出: 8 解释: 8 个乘积小于 100 的子数组分别为: [10], [5], [2], [6], [10,5], [5,2], [2,6], [5,2,6]。 需要注意的是 [10,5,...

[LeetCode]495. 提莫攻击

提莫攻击

题目描述 在《英雄联盟》的世界中,有一个叫 “提莫” 的英雄。他的攻击可以让敌方英雄艾希(编者注:寒冰射手)进入中毒状态。 当提莫攻击艾希,艾希的中毒状态正好持续 duration 秒。 正式地讲,提莫在 t 发起发起攻击意味着艾希在时间区间 [t, t + duration - 1](含 t 和 t + duration - 1)处于中毒状态。如果提莫在中毒影响结束 前 再次攻击,中...

[LeetCode]130. 被围绕的区域

围绕区域

题目描述 给你一个 m x n 的矩阵 board ,由若干字符 ‘X’ 和 ‘O’ ,找到所有被 ‘X’ 围绕的区域,并将这些区域里所有的 ‘O’ 用 ‘X’ 填充。 Example1: 输入:board = [[“X”,”X”,”X”,”X”],[“X”,”O”,”O”,”X”],[“X”,”X”,”O”,”X”],[“X”,”O”,”X”,”X”]] 输出:[[“X”...

[LeetCode]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 ...

[LeetCode]384. Shuffle an Array

实现洗牌算法

题目描述 Shuffle a set of numbers without duplicates. Example1: // Init an array with set 1, 2, and 3. int[] nums = {1,2,3}; Solution solution = new Solution(nums); // Shuff...

[LeetCode]131. Palindrome Partitioning

输出所有子串的回文序列

题目描述 Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Example1: Input: "aab" Output: [ ...

[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 statio...

[LeetCode]84. Largest Rectangle in Histogram

递增栈

题目描述 Given n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where...