LintCode笔记
墩仔
nononononononononO
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LintCode:两个字符串是变位词
写出一个函数 anagram(s, t) 去判断两个字符串是否是颠倒字母顺序构成的 样例: 给出 s="abcd",t="dcab",返回 true 代码: public class Solution { /** * @param s: The first string * @param b: The second string *原创 2015-12-11 13:14:40 · 739 阅读 · 0 评论 -
LintCode:二叉树的后序遍历
给出一棵二叉树,返回其节点值的后序遍历。 样例 给出一棵二叉树 {1,#,2,3}, 1 \ 2 / 3 返回 [3,2,1] 挑战 你能使用非递归实现么? /** * Definition of TreeNode: * public class TreeNode { * public int val;原创 2015-12-15 16:19:53 · 437 阅读 · 0 评论 -
LintCode:把排序数组转换为高度最小的二叉搜索树
给一个排序数组(从小到大),将其转换为一棵高度最小的排序二叉树。 样例 给出数组 [1,2,3,4,5,6,7], 返回 4 / \ 2 6 / \ / \ 1 3 5 7 挑战 可能有多个答案,返回任意一个即可 /** * Definition of TreeNode: * public class Tree原创 2015-12-15 15:11:55 · 523 阅读 · 0 评论 -
斐波纳契数列
要求: 查找斐波纳契数列中第 N 个数。 所谓的斐波纳契数列是指: 前2个数是 0 和 1 。第 i 个数是第 i-1 个数和第i-2 个数的和。 斐波纳契数列的前10个数字是: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 ... 斐波那契数列通项公式: F(n)=F(n-1)+F(n-2) 代码(非递归实现):class Solution {原创 2015-12-01 17:20:20 · 520 阅读 · 0 评论 -
Remove Linked List Elements
要求 Remove all elements from a linked list of integers that have value val. 样例 Given 1->2->3->3->4->5->3, val = 3, you should return the list as 1->2->4->5 代码 public class So原创 2015-12-01 16:35:30 · 379 阅读 · 0 评论 -
Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head. 样例 Given 1->2->3->4, you should return the list as 2->1->4->3. 挑战 Your algorithm should use only constant space. Y原创 2015-12-08 14:39:52 · 314 阅读 · 0 评论 -
LintCode: x的平方根
实现 int sqrt(int x) 函数,计算并返回 x 的平方根。 样例 sqrt(3) = 1 sqrt(4) = 2 sqrt(5) = 2 sqrt(10) = 3 挑战 O(log(x)) class Solution { /** * @param x: An integer * @return: The sq原创 2015-12-08 16:19:02 · 547 阅读 · 0 评论 -
二分查找
给定一个排序的整数数组(升序)和一个要查找的整数target,用O(logn)的时间查找到target第一次出现的下标(从0开始),如果target不存在于数组中,返回-1。 样例 在数组 [1, 2, 3, 3, 4, 5, 10] 中二分查找3,返回2。 挑战 如果数组中的整数个数超过了2^32,你的算法是否会出错? class Solution {原创 2015-12-07 11:28:17 · 674 阅读 · 0 评论
分享