- 博客(105)
- 收藏
- 关注
原创 按下开机键,电脑都做了哪些事
从打开电源到开始操作,计算机的启动是一个非常复杂的过程。先问一个问题,"启动"用英语怎么说?回答是boot。可是,boot原来的意思是靴子,"启动"与靴子有什么关系呢? 原来,这里的boot是bootstrap(鞋带)的缩写,它来自一句谚语: "pull oneself up by one's bootstraps"字面意思是"拽着鞋带把自己拉起来",这当然是不可能的事情。最
2016-04-27 17:02:03 1586 1
原创 29. Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.思路:采用累加法,设置一个sum和一个count,下面演示一下累加法的过程 比如26/5sum=5,count=1 dividend=26;sum=
2016-04-25 00:48:16 559
原创 151. Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place
2016-04-25 00:36:20 432
原创 179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve
2016-04-25 00:22:01 318
原创 3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "
2016-04-24 20:36:36 327
原创 152. Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest product.For example, given the array [2,3,-2,4],the contiguous subarray [2,3] has the larges
2016-04-24 20:30:47 318
原创 324. Wiggle Sort II
Given an unsorted array nums, reorder it such that nums[0] nums[2] .Example:(1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6]. (2) Given nums = [1, 3, 2, 2, 3
2016-04-24 20:20:51 632
原创 143. Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it t
2016-04-24 20:13:45 293
原创 61. Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.思路:旋转链表,非常常规的题了,只是需要注意k可能大于链表
2016-04-24 20:07:38 281
原创 5. Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.思路:i为中心位置向两边扩展,注意a
2016-04-24 19:59:09 266
原创 2. Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link
2016-04-24 19:54:57 253
原创 93. Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order
2016-04-24 19:50:29 289
原创 221. Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0
2016-04-24 19:47:28 218
原创 150. Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",
2016-04-24 19:39:58 276
原创 18. 4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Element
2016-04-24 19:24:06 266
原创 228. Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].思路:设置一个start和end,开始时都指向0,然后end往后走,直到nums[end]!=nu
2016-04-24 19:18:28 237
原创 148. Sort List
Sort a linked list in O(n log n) time using constant space complexity.思路:可以参考归并排序的思想,一半一半的使之有序,然后归并代码如下(已通过leetcode)public class Solution { public ListNode sortList(ListNode head) { i
2016-04-24 19:15:14 252
原创 322. Coin Change
ou are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money c
2016-04-24 19:11:58 268
原创 222. Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes.Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely fille
2016-04-24 19:05:24 299
原创 60. Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""3
2016-04-24 18:59:31 271
原创 139. Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["leet"
2016-04-24 18:47:26 235
原创 306. Additive Number
Additive number is a string whose digits can form additive sequence.A valid additive sequence should contain at least three numbers. Except for the first two numbers, each subsequent number in the
2016-04-24 18:39:41 233
原创 257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]思路:
2016-04-24 18:35:57 295
原创 阿里菜鸟java岗面试
最近一直在忙微软的面试,今天下午突然接到了阿里的面试电话,整理一下问题,留个记录吧1 各种路径选择算法2 图论中的搜索算法3 红黑树和B树4 堆排序的建堆和按从小到大输出堆还有时间复杂度5 操作系统 死锁的四个条件 如何解决死锁6 线程可见性7 tcp的断开连接8 c++与java的不同,多继承单继承这些9 3类加载器和父加载机制10 jdk jar包用到的
2016-04-23 23:54:26 5529
原创 229. Majority Element II
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.思路: 跟majority element一样,还是投票法,因为求个数大于n/3的数字,我们知
2016-04-23 14:51:05 294
原创 209. Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return 0 instead.For example, given the array [2,3
2016-04-23 14:45:38 258
原创 134. 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
2016-04-23 14:38:14 207
原创 49. Group Anagrams
Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]Note:
2016-04-23 14:34:00 194
原创 131. Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","b"],
2016-04-23 14:28:05 206
原创 160. 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:A: a1 → a2 ↘
2016-04-23 14:25:04 200
原创 36. Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille
2016-04-23 14:23:14 218
原创 111. Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.思路:就是一个求最小路径长度代码如下(已通过leetcode
2016-04-23 14:21:08 207
原创 172. Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.思路:就是找5的个数 比如 26有5,10,15,20 25 一共6个5(因为25有2个5)代码如下(已通过leetcode)
2016-04-23 14:12:53 180
原创 119. 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].思路:就是跟上题一模一样的思路,这里就不在赘述了代码如下(已通过leetcode)public class Solution { public L
2016-04-23 14:09:41 246
原创 118. Pascal's 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]]对于当前的list,就是先添加一下
2016-04-23 14:08:07 193
原创 66. Plus One
Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.思路:就是设置一个carry位看有没有进
2016-04-23 14:04:04 192
原创 107. Binary Tree Level Order Traversal II
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 example:Given binary tree {3,9,20,#,#,15,7},
2016-04-23 14:01:26 208
原创 102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20
2016-04-23 13:55:27 215
原创 330. Patching Array
Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the array. Re
2016-04-21 11:42:45 251
原创 200. Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assu
2016-04-21 11:37:33 199
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人