What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant extra space.For example,Given ...

Apparently BFS is the most obvious one.. but it is not that simple - only constant extra space is provided.Then the only strategy to take is recursion...

Classic recursion\pruning problem. We can use O(n) space: A[i] = j means [i,j] is occupied.class Solution {public: int ret; bool isValid(int *A,...

What's xxxAn SVM model is a representation of the examples as points in space, mapped so that the examples of the separate categories are divided by a...

Determine whether an integer is a palindrome. Do this without extra space. 判断一个int值是否为回文数。 本题有几点需要注意： （1）不能用额外存储空间，也就是说只能用常数空间解决；诸如将int转换为string再去比较字符是不可行的； （2）判断回文数的方法有两个：从中间开始向两头判断、从两头向中间判断；后者更简...

Given a stringsconsists of upper/lower-case alphabets and empty space characters' ', return the length of last word in the string.If the last word doe...

Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for a...

Linked List CycleGiven a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?算法思路1：快慢指针，当两个指针相遇，则表示有环，...

© 2014 mamicode.com 版权所有 京ICP备13008772号-2