摘要:题目要求 X is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from X. Each digit must be r
阅读全文
摘要:题目要求 Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL 题目分析及思路 给定一个单链表,要求得到它的逆序。可以使用列表对链表结点进行保存,之后新建一个列表对链
阅读全文
摘要:题目要求 You are given a data structure of employee information, which includes the employee's unique id, his importance value and his direct subordinates
阅读全文
摘要:题目要求 Given two arrays, write a function to compute their intersection. 题目分析及思路 给定两个数组,要求得到它们之中共同拥有的元素列表(列表中元素是唯一的)。可以将所给数组转成集合,利用集合的交集的概念,最后将结果转成列表即可。
阅读全文
摘要:题目要求 Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. 题目分析及思路 给定一个非负整数,要求将它的各位数相加得到一个新数并对该新数重复进行这样
阅读全文
摘要:题目要求 Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to comple
阅读全文
摘要:题目要求 Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements. 题目分析及思路 给定一
阅读全文
摘要:题目要求 Given a binary array, find the maximum number of consecutive 1s in this array. 题目分析及思路 给定一个01数组,要求找到这个数组中连续1的最大长度。可以考虑0的位置,结合数组切片,循环进行。要记得把最后数组的长
阅读全文
摘要:题目要求 An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is monotone increasing if for all i <= j, A[i] <= A[
阅读全文
摘要:题目要求 Design a HashMap without using any built-in hash table libraries. To be specific, your design should include these functions: put(key, value) : I
阅读全文
摘要:题目要求 We want to use quad trees to store an N x N boolean grid. Each cell in the grid can only be true or false. The root node represents the whole gri
阅读全文
摘要:题目要求 You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points. 题目分析及思路 给定一个平面上的一组点,要求
阅读全文
摘要:题目要求 You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3
阅读全文
摘要:题目要求 Every non-negative integer N has a binary representation. For example, 5 can be represented as "101" in binary, 11 as "1011" in binary, and so on
阅读全文
摘要:题目要求 Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible
阅读全文
摘要:题目要求 On a N * N grid, we place some 1 * 1 * 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j). Return
阅读全文
摘要:题目要求 Given a string S, return the "reversed" string where all characters that are not a letter stay in the same place, and all letters reverse their p
阅读全文
摘要:题目要求 A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to conver
阅读全文
摘要:题目要求 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
阅读全文
摘要:题目要求 In an alien language, surprisingly they also use english lowercase letters, but possibly in a different order. The order of the alphabet is some
阅读全文
摘要:题目要求 Given an array A of positive lengths, return the largest perimeter of a triangle with non-zero area, formed from 3 of these lengths. If it is imp
阅读全文
摘要:题目要求 Invert a binary tree. 题目分析及思路 给定一棵二叉树,要求每一层的结点逆序。可以使用递归的思想将左右子树互换。 python代码 # Definition for a binary tree node. # class TreeNode: # def __init__
阅读全文
摘要:题目要求 Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. 题目分析及思路 给定一个正整数,
阅读全文
摘要:题目要求 Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary represent
阅读全文
摘要:题目要求 Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array. 题目分析及思路 给定一棵非空二叉树,要求以列表的形式返回每一层结点值的平均
阅读全文
摘要:题目要求 Given an n-ary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). 题目分析及思路 给定一棵N叉树,要求返回它的层次遍历结
阅读全文
摘要:题目要求 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
阅读全文
摘要:题目要求 You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for n
阅读全文
摘要:题目要求 Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the
阅读全文
摘要:题目要求 You have an array of logs. Each log is a space delimited string of words. For each log, the first word in each log is an alphanumeric identifier.
阅读全文
摘要:题目要求 Given a non-empty array of integers, every element appears twice except for one. Find that single one. 题目分析及思路 给定一个非空整数数组,除了一个元素只出现一次外,其余元素均出现两次。
阅读全文