原文链接: https://leetcode-cn.com/problems/k-radius-subarray-averages 英文原文You are given a 0-indexed array nums of n integers, and an integer k. The k-radius average for a subarray of nums centered at some index i with the radius k is the average of all e…
分类详情
中等 分类
原文链接: https://leetcode-cn.com/problems/removing-minimum-and-maximum-from-array 英文原文You are given a 0-indexed array of distinct integers nums. There is an element in nums that has the lowest value and an element that has the highest value. We call the…
原文链接: https://leetcode-cn.com/problems/programmable-robot 中文题目力扣团队买了一个可编程机器人,机器人初始位置在原点(0, 0)。小伙伴事先给机器人输入一串指令command,机器人就会无限循环这条指令的步骤进行移动。指令有两种: U: 向y轴正方向移动一格 R: 向x轴正方向移动一格。 不幸的是,在 xy 平面上还有一些障碍物,他们的坐标用obstacles表示。机器人一旦碰到障碍物就会被损毁。 给定终点坐标(x, y),返回机器人能否…
原文链接: https://leetcode-cn.com/problems/route-between-nodes-lcci 英文原文Given a directed graph, design an algorithm to find out whether there is a route between two nodes. Example1: Input: n = 3, graph = [[0, 1], [0, 2], [1, 2], [1, 2]], start = 0, targe…
原文链接: https://leetcode-cn.com/problems/sort-of-stacks-lcci 英文原文Write a program to sort a stack such that the smallest items are on the top. You can use an additional temporary stack, but you may not copy the elements into any other data structure (su…
原文链接: https://leetcode-cn.com/problems/list-of-depth-lcci 英文原文Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth (e.g., if you have a tree with depth D, you'll have D linked lists). Return a array cont…
原文链接: https://leetcode-cn.com/problems/legal-binary-search-tree-lcci 英文原文Implement a function to check if a binary tree is a binary search tree. Example 1: Input: 2 / \ 1 3 Output: true Example 2: Input: 5 / \ 1 4 / \ 3 6 Output: false Explanation: I…
原文链接: https://leetcode-cn.com/problems/successor-lcci 英文原文Write an algorithm to find the "next" node (i.e., in-order successor) of a given node in a binary search tree. Return null if there's no "next" node for the given node. Example 1: Input: root …
原文链接: https://leetcode-cn.com/problems/linked-list-cycle-lcci 英文原文Given a circular linked list, implement an algorithm that returns the node at the beginning of the loop. Circular linked list: A (corrupt) linked list in which a node's next pointer po…
原文链接: https://leetcode-cn.com/problems/first-common-ancestor-lcci 英文原文Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. NOTE: This is not necessaril…
原文链接: https://leetcode-cn.com/problems/closed-number-lcci 英文原文Given a positive integer, print the next smallest and the next largest number that have the same number of 1 bits in their binary representation. Example1: Input: num = 2 (0b10) Output: [4…
原文链接: https://leetcode-cn.com/problems/rotate-matrix-lcci 英文原文Given an image represented by an N x N matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place? Example 1: Given matrix…
原文链接: https://leetcode-cn.com/problems/zero-matrix-lcci 英文原文Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0. Example 1: Input: [ [1,1,1], [1,0,1], [1,1,1] ] Output: [ [1,0,1], [0,0,0], [1,0,1] …
原文链接: https://leetcode-cn.com/problems/sum-lists-lcci 英文原文You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1's digit is at the head of the list. Write a …
原文链接: https://leetcode-cn.com/problems/stack-of-plates-lcci 英文原文Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshol…
原文链接: https://leetcode-cn.com/problems/draw-line-lcci 英文原文A monochrome screen is stored as a single array of int, allowing 32 consecutive pixels to be stored in one int. The screen has width w, where w is divisible by 32 (that is, no byte will be spl…
原文链接: https://leetcode-cn.com/problems/power-set-lcci 英文原文Write a method to return all subsets of a set. The elements in a set are pairwise distinct. Note: The result set should not contain duplicated subsets. Example: Input: nums = [1,2,3] Output: […
原文链接: https://leetcode-cn.com/problems/recursive-mulitply-lcci 英文原文Write a recursive function to multiply two positive integers without using the * operator. You can use addition, subtraction, and bit shifting, but you should minimize the number of t…
原文链接: https://leetcode-cn.com/problems/bracket-lcci 英文原文Implement an algorithm to print all valid (e.g., properly opened and closed) combinations of n pairs of parentheses. Note: The result set should not contain duplicated subsets. For example, give…
原文链接: https://leetcode-cn.com/problems/bianry-number-to-string-lcci 英文原文Given a real number between 0 and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at …
原文链接: https://leetcode-cn.com/problems/check-subtree-lcci 英文原文T1 and T2 are two very large binary trees. Create an algorithm to determine if T2 is a subtree of T1. A tree T2 is a subtree of T1 if there exists a node n in T1 such that the subtree of n…
原文链接: https://leetcode-cn.com/problems/coin-lcci 英文原文Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents), and pennies (1 cent), write code to calculate the number of ways of representing n cents. (The result may be la…
原文链接: https://leetcode-cn.com/problems/search-rotate-array-lcci 英文原文Given a sorted array of n integers that has been rotated an unknown number of times, write code to find an element in the array. You may assume that the array was originally sorted i…
原文链接: https://leetcode-cn.com/problems/permutation-i-lcci 英文原文Write a method to compute all permutations of a string of unique characters. Example1: Input: S = "qwe" Output: ["qwe", "qew", "wqe", "weq", "ewq", "eqw"] Example2: Input: S = "ab" Output:…
原文链接: https://leetcode-cn.com/problems/swap-numbers-lcci 英文原文Write a function to swap a number in place (that is, without temporary variables). Example: Input: numbers = [1,2] Output: [2,1] Note: numbers.length == 2 -2147483647 <= numbers[i] <= 21474…
原文链接: https://leetcode-cn.com/problems/words-frequency-lcci 英文原文Design a method to find the frequency of occurrences of any given word in a book. What if we were running this algorithm multiple times? You should implement following methods: WordsFreq…
原文链接: https://leetcode-cn.com/problems/tic-tac-toe-lcci 英文原文Design an algorithm to figure out if someone has won a game of tic-tac-toe. Input is a string array of size N x N, including characters " ", "X" and "O", where " " represents a empty grid. T…
原文链接: https://leetcode-cn.com/problems/smallest-difference-lcci 英文原文Given two arrays of integers, compute the pair of values (one value in each array) with the smallest (non-negative) difference. Return the difference. Example: Input: {1, 3, 15, 11, …
原文链接: https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof 中文题目在一个 n * m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个高效的函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 示例: 现有矩阵 matrix 如下: [ [1, 4, 7, 11, 15], [2, 5, 8, 12, 19], [3, 6, 9, 16, 2…
原文链接: https://leetcode-cn.com/problems/ju-zhen-zhong-de-lu-jing-lcof 中文题目给定一个 m x n 二维字符网格 board 和一个字符串单词 word 。如果 word 存在于网格中,返回 true ;否则,返回 false 。 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中“相邻”单元格是那些水平相邻或垂直相邻的单元格。同一个单元格内的字母不允许被重复使用。 例如,在下面的 3×4 的矩阵中包含单词 "ABCCED…