`
carlosten
  • 浏览: 3431 次
  • 性别: Icon_minigender_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.   使用遍历二叉树的某一种方法(这里使用先序遍历),递归的遍历两棵树,同时比较节点的值,不同则代表两棵树不一样。遍历完毕如果都相同,则两棵树相同。   class Solution { public: ...
题目描述: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1->1->2->3, return 
题目描述: Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100".  
  题目描述: 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 to hold additional elements from B. The number of elements initialized in A and B are m and n respectively.   新建一个数组,将原来两个数组从小到大加入这个数组中,最后再复制到A数组里。其实可以有更省空间和时间的方法。从将A ...
题目描述: Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321   翻转数字,读入数字之后分别得到最低位,次低位...,每次添加一位,上一位跟着*10,增大一位。  Bonus: 10100 这样的数,由于result初始 ...
题目描述: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?   实际上是斐波那契数列,第n steps的方法为第n-1 steps和第n-2 steps的方法数之和。 处理边界条件,即n为1和n为2的时候,直接返回结果。   class solution{ public: int climbS ...
Global site tag (gtag.js) - Google Analytics