`
淡淡的一抹
  • 浏览: 19087 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表
题目描述 Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 解题思路 本题是二叉树的遍历题,但是在深度优先和广度优先上需要进行考虑。如果采用深度优先算法的话,并不能保证另一颗子树的情况,浪费时间,因此采用广度优先算法。本题还是采用两个辅助队列的方式。 自己的代码 package leetcode; import jav ...
题目描述 Given a linked list, remove the nth node from the end of list and return its head. For example,    Given linked list: 1->2->3->4->5, and n = 2.    After removing the second node from the end, the linked list becomes 1->2->3->5. Note: Given n will always be valid. Try to ...

Path Sum

题目描述 Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. For example: Given the below binary tree and sum = 22,               5              / \             4   8            /   / \           11  13  4 ...
题目描述 Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree {3,9,20,#,#,15,7},     3    / \   9  20     /  \    15   7 return its bottom-up level order traversal as: [   [15,7 ...
题目描述 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 return its level order traversal as: [   [3],   [9,20],   [15,7] ] 解题思路 本题的解题思路还是二叉 ...

Pascal's Triangle II

题目描述 Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 解题思路 本题是在上一题Pascal's Triangle的基础上稍作修改而完成的,需要注意的是给定的下标是从零开始的,因此代码在上一题代码的基础上进行了调整。 自己的代码 package leetcode; import ...

Pascal's Triangle

题目描述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [      [1],     [1,1],    [1,2,1],   [1,3,3,1], [1,4,6,4,1] ] 解题思路 本题的目的是根据不同的数字,构建不同的三角形。需要注意的就是每个数字的产生特点。 自己的代码 package leetcode; import java.util.ArrayList; import java.util.List; ...

Plus One

题目描述 Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list 解题思路 本题是将一个十位数按位存储到数组中,然后加一后将结果数组输出。主要的问题在如果有进位的情况需要特殊处理。 自己的代码 package leetcode; import java.util.Arrays; public ...

Merge Sorted Array

题目描述 Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space (size that is greater or equal to m + n) to hold additional elements from B. The number of elements initialized in A and B are m and n respectively. 解题思路 本题根据题目提示,想到了用插入排序来 ...

Symmetric Tree

题目描述 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric:     1    / \   2   2 / \ / \ 3  4 4  3 But the following is not:     1    / \   2   2    \   \    3    3 解题思路 (1) 本题想到的解题思路是树的层序遍历,然后比较同一层上的元素是否是对称的。 ...
题目描述 Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. For example, Given input array A = [1,1,2], Your function should return lengt ...

Balanced Binary Tree

题目描述 Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 解题思路 是一个关于二叉树的基本题,判断一颗树是否是平衡二叉树。 相关知识 (1)平衡二叉树的概念 平衡二叉树(Balanced Binary Tree), ...

Remove Element

题目描述 Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length. 解题思路 将提供的元素去掉,并返回剩余数组的长度。 注意问题 1 注意不是只要求返回剩余数组的长度,而且必须是将元素都移动到数组的长度以内。 2 注意去除了多少个元素,就将元素前移几位。 代码示例 ...
题目描述 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. 解题思路 对比两个表头的元素,将较小者插入新的链表中。 源代码 package leetcode; /*private class ListNode { int val; ListNode next; ListNode(int x) { va ...

CSS选择器的常用规则

    博客分类:
  • CSS
 
CSS选择器的常用规则 (1) 组规则 语法:选择符1,选择符2,...,选择符n{属性1:值1; 属性2:值2;...;属性n:值n;} 示例: /*定义H1的格式*/ H1 { font-weight: bold;/*字体的粗细,bold指粗体*/ font-size: 12pt;/*字体尺寸,现在一 ...
Global site tag (gtag.js) - Google Analytics