判断一棵树是不是平衡二叉树,之前做过,还有点印象,用一个函数返回树的高度,如果是-1的话,就说明子树不平衡。1A很开心~ 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * T...
分类:
其他好文 时间:
2014-07-07 13:56:05
阅读次数:
180
What is the Median?
The Problem
Median plays an important role in the world of statistics. By definition, it is a value which divides an array into two equal parts. In this problem you are ...
分类:
其他好文 时间:
2014-07-03 17:43:53
阅读次数:
250
Sort a linked list in O(n log n)
time using constant space complexity.
看到O(n log n)的排序算法,适合单链表的首先想到的就是归并排序
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* Lis...
分类:
其他好文 时间:
2014-07-02 08:47:34
阅读次数:
239
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first
two lists.
代码如下:
* Definition for singly-linked list.
* struct L...
分类:
其他好文 时间:
2014-07-02 07:23:59
阅读次数:
159
做完这道题,只能说基本功很重要,数组中套数组就不会用了,过几天吧1做了,看自己到底等没。https://oj.leetcode.com/problems/binary-tree-level-order-traversal-ii/import java.util.*;/** * Definition ...
分类:
编程语言 时间:
2014-07-01 13:30:53
阅读次数:
300
秒杀/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = ...
分类:
编程语言 时间:
2014-07-01 13:16:49
阅读次数:
174
https://oj.leetcode.com/problems/path-sum//** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNod...
分类:
编程语言 时间:
2014-07-01 13:09:20
阅读次数:
198
https://oj.leetcode.com/problems/validate-binary-search-tree/1.中序遍历是否有序/** * Definition for binary tree * public class TreeNode { * int val; * ...
分类:
编程语言 时间:
2014-07-01 12:20:06
阅读次数:
173
题目
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
方法
/**
* Definition for singly-linked list.
* class ListNode {
...
分类:
其他好文 时间:
2014-07-01 11:31:40
阅读次数:
178
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *...
分类:
其他好文 时间:
2014-06-30 23:36:56
阅读次数:
211