- 博客(80)
- 收藏
- 关注
原创 Leetcode之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 stat
2013-09-30 06:06:44 3846 1
原创 Leetcode之First Missing Positive
题目:Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses
2013-09-20 15:17:40 359
原创 Interleaving String的解析
Interleaving String的两种面试题:1. 给定两个String, 求出所有interleaving string的可能2. 给定两个String,判断第三个String是不是他们的interleaving string第一感觉必然是递归,但是two pointer和permutation的思路还是一闪而过。 Two Pointer是对的,但是permutatio
2013-09-13 05:59:19 504 1
原创 字典找单词路径的更新版
题目在leetcode上和白书(18-10)上都出现过,不再赘述。为什么还要再拿出来写一遍?以前做leetcode的解法只要求返回总共需要的步数,最近看了白书,发现只要在里面加入一个backtracking的map结构,就可以返回单词变化路径的list。Java解法如下:class Test{ public static void main(String[] args)
2013-09-02 06:46:59 344
原创 Suffix Tree的简单构造法(P.S. strStr()的suffix解法)
这里介绍的实现方法是O(N*N)的,目前广泛流行的是O(N)的实现方法,但是由于结构复杂,超出了我目前的实力范围,因此只求把O(N*N)的展示明白就OK了,好吧。Suffix Tree实现代码:
2013-08-31 03:07:04 485
原创 BST的Java实现模板
记录下自己的BST写法,技术指数为负,还请直接跳过。和Trie的类方法一样,递归非递归的插入搜索方法,和唯一tricky一点点的remove()方法。remove()的方法没有用递归,然后还可以返回另一边的successor(这里返回的是右子树的successor,左子树的successor和这个对称,并且同样可以运行成功)。BST的Java代码实现:class Test{
2013-08-30 07:46:12 314
原创 计算一个范围内2出现的次数
Topic:面经题目:Write a method to count the number of 2s between 0 and n. (cc150: 18-4)Code:
2013-08-27 01:44:28 561
原创 Add Two Numbers
Topic: Math Function题目:Write a function that adds two numbers. You should not use '+' or any arithmetic operators.Code:
2013-08-26 02:33:39 350
原创 通过一道面试题对于BFS,DFS的简单思考
Topic:面经题目:给定一个二维数组,可以看做其中的1被0包围,求数组中有几堆1?Code:class Test{ public static void main(String[] args){ int[][] matrix = { {1, 1, 0, 1}, {0, 1, 1, 0}, {0, 0, 0, 1}, {0, 1, 1,
2013-08-24 14:06:56 473
原创 Convert Binary Tree into Doubly Linked List
Topic:面经题目:Convert Binary Tree into Doubly Linked List.Code:class Solution{ //level-order编排doubly linked list public void levelList(Node root){ if(root==null) return; Queue q = new
2013-08-24 12:27:16 415
原创 Check If Singly List Is Circular
主题:面经题目:Given a singly list. Check if it is circular.Code:import java.util.*;class Test{ public static void main(String[] args){ Node n1 = new Node(1); Node n2 = new Node(2); N
2013-08-17 14:10:26 359
原创 求数组中唯一奇数次出现的数
主题:面经题目:An array of integers, only one integer appears odd times, all others appear even times, find itCode:import java.util.*;class Test{ public static void main(String[] args){
2013-08-17 13:38:19 403
原创 时针分针角度
主题:面经题目:In a clock, calculate the angle between hour and minute handle Code:class Test{ public static void main(String[] args){ Solution sol = new Solution(); int h = 6, min = 45
2013-08-17 02:45:55 337
原创 Pattern Matching
主题:面经题目:Pattern Matching, if '.' is used as a wildcard, which means '.'can represent any character. Code:
2013-08-16 13:37:31 339
原创 Check if it's BST
主题:面经题目:Check whether a binary tree is BST(if the binary tree is very large, you can not simply in-order print all the nodes out.) Code:class Solution{ public boolean isBST(Node root, N
2013-08-16 13:35:17 365
原创 面经:Depth of Binary Tree
主题:面经题目:Calculate the depth of Binary Tree.Code:class Solution{ //树的最大深度 public int getMaxDep(Node root){ if(root == null) return 0; return Math.max(getMaxDep(root.left), getMaxDep(r
2013-08-16 08:51:19 306
原创 面经:求给定范围的数组中有重复的单个元素
主题:面经题目:An array of integer of size N, all the elements are from range[1,N-1], one is duplicate, find it.代码:import java.util.*;class Test{ public static void main(String[] args){ S
2013-08-16 08:22:17 347
原创 面经:求给定范围数组中缺少的单个元素
主题:面经题目:An array of integer of size N-1, all the elements are from range[1,N], one is missing, find it.代码:import java.util.*;class Test{ public static void main(String[] args){ S
2013-08-16 08:08:16 362
原创 面经:复制多指针链表
主题:面经Question:Given a list of nodes , Node class has fields value(of type integer) , next(of type Node) , other(of type Node) where next points to next node and other points to some arbitrary no
2013-08-16 05:20:11 362
原创 题目待解决
1) System Design question . Implement "File" java class. He went deep in to the design specifics , asked me to design cache , handle parallel access , efficient data structures to do it etc..,2)
2013-08-16 02:38:13 363
原创 Longest Common Subsequence
主题:面经Question:Find the longest common sub-sequence in two strings, and return its length.分析:youtube上三哥的视频做的不错,讲解清晰。这道题可以用递归,可以用DP。思想相差不多,base case是有一个string遍历到无,返回零;其他情况有,当前遍历位置两个字符串char
2013-08-16 02:27:17 388
原创 Lowest Common Ancestor of two nodes in a binary tree
Question:Find out the Lowest Common Ancestor of two nodes in a Binary Tree.分析:
2013-08-15 14:55:10 411
原创 Leetcode&面经之Minimum Window Substring
Topic:面经题目:leetcode上的原题是:Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T
2013-08-15 07:02:27 459
原创 Leetcode之Binary Tree Inorder Traverse(Iteratively)
Question:Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Re
2013-08-12 07:18:34 308
原创 Leetcode之Partition List
Question:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal tox.You should preserve the original relative order of the
2013-08-11 14:24:58 396
原创 Leetcode之Remove Duplicates from Sorted List II
Question: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->4->4->5, return 1->2
2013-08-11 10:48:21 315
原创 Leetcode之Search for a Range
Question:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the targe
2013-08-11 02:07:39 342
原创 Leetcode之DP+滚动数组之Unique Path, Minimum Sum Path
题目:1.A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is tryin
2013-08-10 10:55:27 609
原创 Leetcode之Maximum Subarray
题目:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−
2013-08-10 03:08:23 449
原创 Leetcode之Multiply Strings
专题:数学运算法Question:Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.» Solve this
2013-08-09 15:34:14 353
原创 Leetcode之Remove Duplicates from Sorted Array
Question:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do thi
2013-08-09 01:59:07 267
原创 Leetcode之Letter Combinations of a Phone Number
Question:Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.
2013-08-08 14:38:38 307
原创 Leetcode之Decode Ways
Question:A message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digits, determi
2013-08-08 03:44:09 324
原创 Leetcode之Anagram
题目:Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.» Solve this problem方法:注意anagram是颠倒字母顺序组成的新词,区别于palindrome没有任何
2013-08-07 11:51:54 506
原创 Climbing Stairs
Question: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 climb to the top?» Solve this
2013-08-04 06:34:51 249
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人