09 2017 档案
摘要:田忌赛马,大致题意是田忌和国王赛马,赢一局得200元,输一局输掉200元,平局则财产不动。 先输入一个整数N,接下来一行是田忌的N匹马,下一行是国王的N匹马。当N为0时结束。 此题为贪心算法解答,有两种思路。 思路二: 1、开始也是先排序,可以使用sort快排; 2、然后将田忌最大的马与国王进行比较
阅读全文
摘要:Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2
阅读全文
摘要:You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 following types: Each round's operation is permane
阅读全文
摘要: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
阅读全文
摘要:There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every
阅读全文
摘要:Given a non-empty string s, you may delete at most one character. Judge whether you can make it a palindrome. Example 1: Input: "aba" Output: True Exa
阅读全文
摘要:Implement a magic directory with buildDict, and search methods. For the method buildDict, you'll be given a list of non-repetitive words to build a di
阅读全文
摘要:Given an unsorted array of integers, find the length of longest continuous increasing subsequence. Example 1: Example 2: Note: Length of the array wil
阅读全文
摘要:题意大概是: 一个数比如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
阅读全文