随笔分类 -  leetcode

intersection of two linked lists.(两个链表交叉的地方)
摘要:Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: 求两个链表开始重合的地 阅读全文

posted @ 2017-12-22 13:42 夜的第八章 阅读(154) 评论(0) 推荐(0)

min stack
摘要:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. push(x) -- Push element x onto stack. pop() -- Remov 阅读全文

posted @ 2017-12-22 10:51 夜的第八章 阅读(150) 评论(0) 推荐(0)

valid palindrome(回文)
摘要:Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases. For example,"A man, a plan, a canal: Pan 阅读全文

posted @ 2017-12-21 20:09 夜的第八章 阅读(138) 评论(0) 推荐(0)

two sum II
摘要:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function 阅读全文

posted @ 2017-12-21 19:12 夜的第八章 阅读(165) 评论(0) 推荐(0)

Best Time to Buy and Sell Stock i
摘要:Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction 阅读全文

posted @ 2017-12-21 16:49 夜的第八章 阅读(138) 评论(0) 推荐(0)

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 us 阅读全文

posted @ 2017-12-21 16:29 夜的第八章 阅读(111) 评论(0) 推荐(0)

Pascal's Triangle(杨辉三角)
摘要:Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return 思路:动态规划,前面的构建出来了,后面根据某种关系也就可以构建出来。 这个要根据前一行来构建下一 阅读全文

posted @ 2017-12-21 15:28 夜的第八章 阅读(216) 评论(2) 推荐(0)

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. F 阅读全文

posted @ 2017-12-21 14:27 夜的第八章 阅读(147) 评论(0) 推荐(0)

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 dept 阅读全文

posted @ 2017-12-21 13:55 夜的第八章 阅读(216) 评论(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 夜的第八章 阅读(117) 评论(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 夜的第八章 阅读(162) 评论(0) 推荐(0)

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

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

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

posted @ 2017-12-20 15:02 夜的第八章 阅读(261) 评论(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 夜的第八章 阅读(122) 评论(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 夜的第八章 阅读(112) 评论(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 夜的第八章 阅读(1309) 评论(0) 推荐(0)

Implement int sqrt(int x).
摘要:自己设计函数,实现求根号。x是非负整数。 Input: 8 Output: 2 当开出根号后有小数,则省略小数部分。。 思路:只要找到一个数a,a*a<=x而且(a+1)*(a+1)>x,则a就是开根号后的结果。 这里要注意:a*a因为<=x,不会溢出,但是(a+1)*(a+1)则可能会导致溢出。一 阅读全文

posted @ 2017-12-19 21:23 夜的第八章 阅读(155) 评论(0) 推荐(0)

Add Binary
摘要:Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". 我们可以用StringBuiler来存放相加以后的结果,然后在reverse()就行 阅读全文

posted @ 2017-12-19 19:03 夜的第八章 阅读(136) 评论(0) 推荐(0)

Roman to Integer(将罗马数字转成整数)
摘要:Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. 将罗马数字转成阿拉伯数字。需要了解两者对应关系。 罗马数字共有7个,即I(1)、V( 阅读全文

posted @ 2017-12-19 17:01 夜的第八章 阅读(207) 评论(0) 推荐(0)

leetcode刷题指南
摘要:转载自:http://blog.csdn.net/lnho2015/article/details/50962989 以下是我个人做题过程中的一些体会: 1. LeetCode的题库越来越大,截止到目前,已经有321个问题了。对于大多数人来说,没有时间也没有必要把所有题目都做一遍(时间充裕可以随意) 阅读全文

posted @ 2017-12-19 16:12 夜的第八章 阅读(2729) 评论(0) 推荐(0)

导航