2017年12月20日

java中的值传递

摘要: Java中只有值传递,没有引用传递。 Java参数,不管是原始类型还是引用类型,传递的都是副本(有另外一种说法是传值,但是说传副本更好理解吧,传值通常是相对传址而言)。 如果参数类型是原始类型,那么传过来的就是这个参数的一个副本,也就是这个原始参数的值,这个跟之前所谈的传值是一样的。如果在函数中改变 阅读全文

posted @ 2017-12-20 21:01 夜的第八章 阅读(166) 评论(0) 推荐(0) 编辑

Convert Sorted Array to Binary Search Tree(将一个有序数组转换成一颗二叉搜索树)

摘要: Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is d 阅读全文

posted @ 2017-12-20 19:53 夜的第八章 阅读(108) 评论(0) 推荐(0) 编辑

Binary Tree Level Order Traversal II(层序遍历2)

摘要: 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 阅读全文

posted @ 2017-12-20 16:51 夜的第八章 阅读(154) 评论(0) 推荐(0) 编辑

Symmetric Tree 对称树

摘要: 判断一棵二叉树是否为对称的树。如 观察上面的树可以看出:左子树的右子树等于右子树的左子树,左子树的左子树等于右子树的右子树。 首先可以使用递归。递归容易理解 再是可以使用迭代,不用递归。 思路就是向遍历一样,每一层比较,但是不输出,只是在遍历过程中比较。使用广度优先遍历。因为要比较,所以一次取出两个 阅读全文

posted @ 2017-12-20 15:46 夜的第八章 阅读(353) 评论(0) 推荐(0) 编辑

same tree(判断两颗二叉树是否相等)

摘要: Example 2: Example 3: 判断两个二叉树是否相等。 一:使用递归。 二:根据遍历出来的顺序,但是由于遍历右左子树可能有一个为空,会影响结果。 class Solution { StringBuilder sb1=new StringBuilder(); StringBuilder 阅读全文

posted @ 2017-12-20 15:02 夜的第八章 阅读(245) 评论(0) 推荐(0) 编辑

merge sorted array

摘要: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size tha 阅读全文

posted @ 2017-12-20 14:04 夜的第八章 阅读(114) 评论(0) 推荐(0) 编辑

Remove Duplicates from Sorted List

摘要: 删除链表中重复的节点,但是重复的节点得留一个 Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. 阅读全文

posted @ 2017-12-20 10:57 夜的第八章 阅读(104) 评论(0) 推荐(0) 编辑

climbing stairs(爬楼梯)(动态规划)

摘要: 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 cl 阅读全文

posted @ 2017-12-20 10:34 夜的第八章 阅读(1267) 评论(0) 推荐(0) 编辑

导航