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

2014年3月25日

【Leetcode】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 tom+n) to hold additional elements from B. The number of elements initialized in A and B aremandnrespectively.解题思路1:设置一个数组C,依次取A的元素i与B的元素j比较,如果B[j 阅读全文
posted @ 2014-03-25 18:59 UsSam 阅读(118) 评论(0) 推荐(0)
 
【Leetcode】Sum Root to Leaf Numbers
摘要: 题目:Given a binary tree containing digits from0-9only, each root-to-leaf path could represent a number.An example is the root-to-leaf path1->2->3which represents the number123.Find the total sum of all root-to-leaf numbers.For example, 1 / \ 2 3The root-to-leaf path1->2represents the number1 阅读全文
posted @ 2014-03-25 18:13 UsSam 阅读(105) 评论(0) 推荐(0)
 
【Leetcode】Path Sum II
摘要: 题目:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree andsum = 22, 5 / \ 4 8 / / \ 11 13 4 / \ / \ 7 2 5 1return[ [5,4,11... 阅读全文
posted @ 2014-03-25 16:42 UsSam 阅读(107) 评论(0) 推荐(0)
 
【Leetcode】Convert Sorted Array to Binary Search Tree
摘要: 题目:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.解题思路:要建立平衡二叉查找树,只需要采用二分法,将每段数组的中间节点的值存入树节点即可,中间节点左右两段的数组的中间结点又作为该树节点的左右子树节点。代码:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * Tr... 阅读全文
posted @ 2014-03-25 16:11 UsSam 阅读(159) 评论(0) 推荐(0)
 
【Leetcode】Valid Parentheses
摘要: 题目:Given a string containing just the characters'(',')','{','}','['and']', determine if the input string is valid.The brackets must close in the correct order,"()"and"()[]{}"are all valid but"(]"and"([)]"are not. 阅读全文
posted @ 2014-03-25 11:06 UsSam 阅读(117) 评论(0) 推荐(0)
 
 

公告


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