摘要: Given a linked list, determine if it has a cycle in it.简单题,只要知道快慢指针这个技巧就很容易解了。 1 class Solution { 2 public: 3 bool hasCycle(ListNode *head) { 4 ... 阅读全文
posted @ 2015-03-12 23:51 desperadox 阅读(138) 评论(0) 推荐(0) 编辑
摘要: Given a column title as appear in an Excel sheet, return its corresponding column number.本质上是一个进制转换问题。1 class Solution {2 public:3 int titleToNumb... 阅读全文
posted @ 2015-03-12 23:45 desperadox 阅读(98) 评论(0) 推荐(0) 编辑
摘要: Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?简单动态规划。判别每个左右子树各有多少种情况,然后相乘就可以了,而且是BST,注意这条件就可以解了。它的状态转移方程为: ... 阅读全文
posted @ 2015-03-12 23:28 desperadox 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 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 an... 阅读全文
posted @ 2015-03-12 22:24 desperadox 阅读(98) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文
posted @ 2015-03-12 22:17 desperadox 阅读(98) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers, every element appearstwiceexcept for one. Find that single one.非常简单的一道题。直接相异或剩下的那个数就是答案。原理是两个相等的数异或的值为0。1 class Solution {... 阅读全文
posted @ 2015-03-12 22:12 desperadox 阅读(172) 评论(0) 推荐(0) 编辑