
leetcode
Turisla
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCodeP079 Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically原创 2015-12-30 15:30:17 · 592 阅读 · 0 评论 -
各种排序算法总结
暂做笔记,以后再详细整理。一、插入排序1、直接插入排序public class InsertSort { public static void insertSort(int[] nums) { int size = nums.length; for (int i = 1; i < size; i++) { if原创 2017-03-13 12:12:13 · 338 阅读 · 0 评论 -
LeetCodeP134 Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to原创 2017-03-13 12:06:07 · 394 阅读 · 0 评论 -
LeetCodeP331 Verify Preorder Serialization of a Binary Tree
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node’s value. If it is a null node, we record using a sentinel value such as #.原创 2017-03-13 11:56:22 · 310 阅读 · 0 评论 -
LeetCode P275 H-Index II
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?Hint:Expected runtime complexity is in O(log n) and the input is sorted.原创 2017-03-13 11:52:19 · 317 阅读 · 0 评论 -
二叉树三种遍历递归及非递归实现
二叉树的三种遍历方式包括:前序遍历中序遍历后序遍历三种遍历的递归方法都非常好实现,而且简单易懂。非递归实现也是通过使用栈来模拟遍历的过程。顺便提一句,能用递归做的,基本都能用栈来实现。前序遍历和中序遍历的非递归写法相对比较简单,只需要模拟遍历过程即可。后序遍历非递归写法比较难,需要借助一个辅助指针来记录右子树是否访问过,以防止重复访问陷入死循环。下面分别给出三种遍历方法的递归和非递原创 2017-03-13 11:48:34 · 655 阅读 · 0 评论 -
腾讯2016研发工程师编程题(两题)
第一题在一组数的编码中,若任意两个相邻的代码只有一位二进制数不同, 则称这种编码为格雷码(Gray Code),请编写一个函数,使用递归的方法生成N位的格雷码。给定一个整数n,请返回n位的格雷码,顺序为从0开始。测试样例:1返回:["0","1"]题解:该题考察格雷码生成规则。具体思想参考我的另一篇博文。本题注意以下几点:1、要求返回的是字符原创 2017-03-13 11:41:25 · 469 阅读 · 0 评论 -
LeetCodeP89 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原创 2017-03-13 11:38:58 · 413 阅读 · 0 评论 -
LeetCodeP22 Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()原创 2017-03-13 11:37:29 · 360 阅读 · 0 评论 -
LeetCode P318 Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case原创 2017-03-13 11:36:06 · 397 阅读 · 0 评论 -
LeetCode P144 Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes’ values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive solution is原创 2015-12-09 19:51:27 · 387 阅读 · 0 评论 -
判断链表是否为回文串以及关于回文串问题的讨论
最近在看程序员面试金典,在链表部分看到有一题问如何判断链表是否是回文串,然后想到白书中也有对最长回文子串的讨论,故想做一点总结。一、判断链表是否为回文串链表的数据结构是这样子滴:public class Node { public int val; public Node next; public Node(int val) {原创 2017-03-13 12:54:32 · 1051 阅读 · 0 评论