随笔分类 - LeetCode
摘要:题目: Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1: Note: 分析: 题目很好理解,就是求二叉树每一层的
阅读全文
摘要:题目: You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontall
阅读全文
摘要:题目: Given an integer, return its base 7 string representation. Example 1: Example 2: Note: The input will be in range of [-1e7, 1e7]. 分析: 给定一个7进制数,求十进
阅读全文
摘要:题目: You are given a string representing an attendance record for a student. The record only contains the following three characters: A student could b
阅读全文
摘要:题目: Given an integer array nums, find the sum of the elements between indices iand j (i ≤ j), inclusive. Example: Note: 分析: 题目的意思很简单,给定一个数组,使用sumRange
阅读全文
摘要:题目: Print a binary tree in an m*n 2D string array following these rules: Example 1: Example 2: Example 3: Note: The height of binary tree is in the ra
阅读全文
摘要:题目: Given an array of 2n integers, your task is to group these integers into npairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum
阅读全文
摘要:题目: In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original d
阅读全文
摘要:题目: Find the sum of all left leaves in a given binary tree. Example: 分析: 给定一颗二叉树,求左叶子节点的和。 重点在于如何判断左叶子节点,如果一个节点的left存在,且left的left和right都为空,那么我们就可以将这个节
阅读全文
摘要:题目: Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has
阅读全文
摘要:题目: The Hamming distance between two integers is the number of positions at which the corresponding bits are different. Given two integers x and y, ca
阅读全文
摘要:题目: There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) afte
阅读全文
摘要:题目: Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would hav
阅读全文
摘要:题目: Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that Alice has, and B[j] is the size of the j-th bar o
阅读全文
摘要:题目: Reverse a singly linked list. Example: Follow up: A linked list can be reversed either iteratively or recursively. Could you implement both? 分析: 分
阅读全文
摘要:题目: Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. To make
阅读全文
摘要:题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in-place, w
阅读全文
摘要:题目: According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician J
阅读全文
摘要:题目: Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: 分析: 每一行,每一列没有相同的数字,每一个3*3的小
阅读全文

浙公网安备 33010602011771号