随笔分类 - Leetcode
摘要:You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following defin
阅读全文
摘要:Given the root of a binary tree, return the sum of every tree node's tilt. The tilt of a tree node is the absolute difference between the sum of all l
阅读全文
摘要:Given an array of integers nums and an integer threshold, we will choose a positive integer divisor and divide all the array by it and sum the result
阅读全文
摘要:You are given a sorted unique integer array nums. Return the smallest sorted list of ranges that cover all the numbers in the array exactly. That is,
阅读全文
摘要:Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. E
阅读全文
摘要:Alice and Bob take turns playing a game, with Alice starting first. Initially, there are n stones in a pile. On each player's turn, that player makes
阅读全文
摘要:Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest l
阅读全文
摘要:Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word (last word means the last appea
阅读全文
摘要:Sort a linked list in O(n log n) time using constant space complexity. Example 1: Input: 4->2->1->3 Output: 1->2->3->4 Example 2: Input: -1->5->3->4->
阅读全文
摘要:You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time
阅读全文
摘要:Compare two version numbers version1 and version2.If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0. You may assume
阅读全文
摘要:Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the fo
阅读全文
摘要:The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a
阅读全文
摘要:Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or
阅读全文
摘要:Given a binary tree, return the sum of values of nodes with even-valued grandparent. (A grandparent of a node is the parent of its parent, if it exist
阅读全文
摘要:Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, yo
阅读全文
摘要:Given a m * n matrix mat and an integer K, return a matrix answer where each answer[i][j] is the sum of all elements mat[r][c] for i - K <= r <= i + K
阅读全文
摘要:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Given linked list -- head = [4,5,1,9], wh
阅读全文
摘要:There are 2N people a company is planning to interview. The cost of flying the i-th person to city A is costs[i][0], and the cost of flying the i-th p
阅读全文