摘要:
题意大概是: 一个数比如242,把所有数字分成两组,而且两组的和相等,那么这个数就是神奇数,此时242,能够分成{2,2}和{4},所以242是神奇数。 题目要求输入n和m求[n,m]区间内神奇数的个数。 思路: 对于任意一个数字,将每一位上的数字保存到数组里,并求所有位上的数字的和sum。然后使用 阅读全文
摘要:
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 hist 阅读全文
摘要:
Given a non-negative integer, you could swap two digits at most once to get the maximum valued number. Return the maximum valued number you could get. 阅读全文
摘要:
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might 阅读全文
摘要:
Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactly two or zero sub-node. 阅读全文
摘要:
Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requ 阅读全文
摘要:
题意大概是给定M×N的棋盘格,从左上到右下,只能向右或者向下走,每走一步需要加上棋盘格子内的数值(有正有负)。 需要随时保证当前的数值>=1。问初始需要最少的值是多少? 思路: 动态规划。用dp[i][j]代表当前最大的数值。首先求出dp[m][n],得出到达右下角的最优值。 然后再回溯求出从左上角 阅读全文
摘要:
If the depth of a tree is smaller than 5, then this tree can be represented by a list of three-digits integers. For each integer in this list: Given a 阅读全文
摘要:
Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element. We define an array is non-decr 阅读全文
摘要:
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For exam 阅读全文