一般的O(n3)肯定不行。在此基础上优化。 发现j,k满足条件时候,(k – j)就是所有 sum <target的情况了。 而一旦>target, 又因为j不能后退,只能k–,那么问…
LeetCode[15] - Flip Game II
这个题目李特是屌炸天的。 我飞了九牛二虎之力(路子对),但是代码写的七荤八素,好长好长好长好长的。 结果正解,三四行就搞定了。真是心有不甘啊。 想法如下: 保证p1能胜利,就必须保持所有p2的move都不能赢。 同时,p…
Day.5 Single Number(136)
问题描述 Given an array of integers, every element appears twice except for one. Find that single one. 思路:利用0和任何数异…
Day 22. Maximum Depth of Binary Tree(104)
问题描述 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest p…
Day1. Rotate Array(189)
问题描述 Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,…
Day3. Remove Element(27)
问题描述 Given an array and a value, remove all instances of that value in-place and return the new length.Do not …
Day18. Number of Segments in a String(434)
问题描述: Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-…
Day15. Reverse Words in a String III(557)
问题描述 Given a string, you need to reverse the order of characters in each word within a sentence while still pr…
Day7. Contains Duplicate(217)
问题描述 Given an array of integers, find if the array contains any duplicates. Your function should return true i…
Day17. Construct String from Binary Tree(606)
You need to construct a string consists of parenthesis and integers from a binary tree with the preorder trave…
Day10. Perfect Number(507)
问题描述 We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors …
Day19. Complex Number Multiplication(537)
问题描述 Given two strings representing two complex numbers. You need to return a string representing their multip…