导入苹果的两个框架是必不可少的环节。。。 代码部分+小解: [cpp] view plain copy - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 题目要求将有序数组转换为一个二元查找树。树的题目大部分都可以采用递归来解决,这道题也不例外。一个二元查找树的左子树上的所有节点都小于根节点,右子树上的所有节点都大于根节点,同时二元查找树左子树和右子树上
Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL. 链表的右旋操作,对于任意k,应该先做一个模n的操作,这样对于大于等于链
Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1]. 全排列问题,详细分析参考这篇文章
Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 判断两个树是否相同,相同的
Write a function to find the longest common prefix string amongst an array of strings. 寻找一组字符串的最长公共前缀,比较简单,直接贴上程序: accepted answer: class Solution {public:string longestCommonPrefix(vector<str
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree {3,9,20,#,#,15,7}, 3/ \9 20/ \15 7
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack. 字符串匹配。 这里给出KMP算法的实现,还可以用BF,BM算法等。 class Solution {public:cha