- 浏览: 201287 次
- 性别:
- 来自: 杭州
最新评论
-
hthhit:
...
回溯算法之N皇后问题(java实现) -
huntfor:
249326109 写道这个算法的复杂度有考虑过么O(n^2) ...
[leetcode]Longest Valid Parentheses -
249326109:
这个算法的复杂度有考虑过么
[leetcode]Longest Valid Parentheses -
huntfor:
249326109 写道又搜到你的了 你怎么搜的,为啥我搜不到 ...
[leetcode]Sort Colors -
249326109:
又搜到你的了
[leetcode]Sort Colors
文章列表
新博文地址:[leetcode]Linked List Cycle II
http://oj.leetcode.com/problems/linked-list-cycle-ii/
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space?
判断一个链表是否含有环,如包含,则返回环的起点。
这道题,有一种很高大上的解法,算法思想具体 ...
新博文地址:[leetcode]Remove Duplicates from Sorted List II
http://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/
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-&g ...
这个算法太。。蛋疼了,新博文地址:[leetcode]Add Binary
http://oj.leetcode.com/problems/add-binary/
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".
刚开始做这道题的时候,考虑的比较简单,首先将二进制字符串转换成int类型,然后将和再转换成字符串形式,然后就悲剧了,int类型溢出,手生了,忘了一 ...
两种思路,详情请参考新博文地址:[leetcode]Gray Code
http://oj.leetcode.com/problems/gray-code/
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray ...
新博文地址:[leetcode]Count and Say
第二遍使用了dfs算法,代码相对稍稍简洁了一丢丢,基本差不多,思想也相仿
http://oj.leetcode.com/problems/count-and-say/
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as "two 1s" ...
http://oj.leetcode.com/problems/roman-to-integer/
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.
题中大意为返回罗马数字(字符串)对应的整数。
我的想法很简单,逐位计算。
首先将I, V,X,L,C,D,M存放起来,并与下标做hash,假如第i位字符的下标小于后面的字符(i+1位)的下标,即小数写在了大数前面,表示减去这个小数。相反,如果第i位字符的下标>=i+1位 ...
新博文地址:[leetcode]Swap Nodes in Pairs
http://oj.leetcode.com/problems/swap-nodes-in-pairs/
Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant sp ...
这个方法略2,新博文地址:[leetcode]Symmetric Tree
http://oj.leetcode.com/problems/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 / \ / \ ...
新博文地址:[leetcode]Merge Sorted Array
http://oj.leetcode.com/problems/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 to m + n) to hold additional elements from B. The numb ...
新博文地址:[leetcode]Single Number II
http://oj.leetcode.com/problems/single-number-ii/
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
...
新博文地址:[leetcode]Pascal's Triangle
http://oj.leetcode.com/problems/pascals-triangle/
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]
跟杨辉三角略像啊,我的想法很直接,逐行求解,存储,如果有好的方法,请分享一下
public ArrayLis ...
平衡二叉树(Balanced binary tree)是由Adelson-velskii 和Landis于1962年提出的,所以又称为AVL树。
先来看定义:
1. 它是一颗空树,或者:2、32. 它的左右两个子树的高度差的绝对值不超过13. 左右两个子树都是一棵平衡二叉树
相关 ...
新博文地址:[leetcode]Balanced Binary Tree
http://oj.leetcode.com/problems/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 of every node never differ by mo ...
新博文地址:[leetcode]Merge Two Sorted Lists
http://oj.leetcode.com/problems/merge-two-sorted-lists/
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first tw
归并两个排好序的链表,主要考察最基本的链表操作,其实跟数组的归并排序没啥区别
一般情况下,有两种解法:时间复杂度都是O(m+n)
...
新博文地址:[leetcode]Populating Next Right Pointers in Each Node
http://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node/
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its ...