• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
UsSam
博客园 | 首页 | 新随笔 | 新文章 | 联系 | 订阅 订阅 | 管理
上一页 1 2 3 4 下一页

2014年3月13日

【Leetcode】Minimum Depth of Binary Tree
摘要: 题目: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.解题思路1:设置一个变量存储当前记录下的最小深度,采用先序遍历的方法访问树的每一个节点,设置一个变量表示当前节点所在的层次,如果一个节点没有子节点,那么就比较该节点的深度与当前的最小深度,选择两者之中较小的作为当前的最小深度。代码:/** * Definition for bi 阅读全文
posted @ 2014-03-13 20:28 UsSam 阅读(133) 评论(0) 推荐(0)
 
 

2014年3月12日

【Leetcode】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 ofeverynode never differ by more than 1.解题思路1(下面给出两种代码实现,代码1和代码2):采用递归的方法,对每一层的节点进行遍历,从叶子节点开始回溯,并从下往上判断每一层的各个是否满足平衡树的条件,并得到以该节 阅读全文
posted @ 2014-03-12 19:20 UsSam 阅读(122) 评论(0) 推荐(0)
 
【Leetcode】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 3But the following is not: 1 / \ 2 2 \ \ 3 3Note:Bonus points if you could solve it both recursively and iter... 阅读全文
posted @ 2014-03-12 15:04 UsSam 阅读(91) 评论(0) 推荐(0)
 
【Leetcode】Same Tree
摘要: 题目: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.解题思路:对两棵树进行遍历即可,这里采用先序遍历的方法。代码:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *... 阅读全文
posted @ 2014-03-12 11:28 UsSam 阅读(136) 评论(0) 推荐(0)
 
 

2014年3月11日

【Leetcode】Remove Duplicates from Sorted List
摘要: 题目:Given a sorted linked list, delete all duplicates such that each element appear onlyonce.For example,Given1->1->2, return1->2.Given1->1->2->3->3, return1->2->3.解题思路:设置两个指针CurrList和NewList,初始化为同一头指针,CurrList不断向链表尾部扫描,如果当前节点的值不是重复值,就将该节点接到NewList尾部。代码:/** * Definition for 阅读全文
posted @ 2014-03-11 19:09 UsSam 阅读(126) 评论(0) 推荐(0)
 
【Leetcode】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.解题思路:要给原有容器表示的数加1,主要需要处理的就是进位的问题。由于是加1,因此只有在当前数字为9的时候采进位。如果在数组的第0个元素上还需要进位,那么就需要在该元素前面增加一个数字1。代码:class Solution {public: v... 阅读全文
posted @ 2014-03-11 16:42 UsSam 阅读(94) 评论(0) 推荐(0)
 
【Leetcode】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.解题思路:设置两个指针pa,pb,pa指针从0开始依次向n-1滑动,当pa指向的元素不是待删除的元素时,将pa指向的元素赋给pb指向的元素,同时pb向前滑动。代码:class Solution {publ 阅读全文
posted @ 2014-03-11 15:58 UsSam 阅读(110) 评论(0) 推荐(0)
 
 

2014年3月7日

【Leetcode】Search in Rotated Sorted Array II
摘要: 题目:Follow up for "Search in Rotated Sorted Array":What ifduplicatesare allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the array.解题思路:该题与Search in Rotated Sorted Array的主要区别在于需要考虑A[low]与A[mid]相等、A[mid]与A[high]相等以及A[low]A[m 阅读全文
posted @ 2014-03-07 22:07 UsSam 阅读(113) 评论(0) 推荐(0)
 
【Leetcode】Search in Rotated Sorted Array
摘要: 题目:Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its index, otherwise return -1.You may assume no duplicate exists in the array.解题思路:数组的查找一般可以使用二分查找法,但是这道题里的 阅读全文
posted @ 2014-03-07 12:39 UsSam 阅读(135) 评论(0) 推荐(0)
 
 

2014年1月24日

修改beacon帧结构(3)帧结构修改示例【Linux内核-OpenWRT】
摘要: 假设现在我需要在Beacon帧中添加一个字段,应该如何添加呢?我们首先来看一看Beacon帧的帧结构(我们需要在Frame Body的保留字段进行字段的添加):Beacon帧是管理帧的一种,管理帧使用信息元素(informationelement,带有数字标签的数据块)来与其他系统交换信息。信息元素是管理帧的可变长组件。信息元素通常包含一个ElementID(元素标识符)字段、一个Length(长度)字段以及一个长度不定的字段,如图所示:查阅802.11规定的信息元素表可以发现,编号为7-15(OpenWRT程序中是8-15)的信息元素是未使用的保留元素,因此可以在Beacon帧中加入该编号范 阅读全文
posted @ 2014-01-24 18:03 UsSam 阅读(1585) 评论(0) 推荐(0)
 
 
上一页 1 2 3 4 下一页

公告


博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3