随笔分类 - 算法&Leetcode
摘要:我手中有一堆扑克牌, 但是观众不知道它的顺序。 1、第一步, 我从牌顶拿出一张牌, 放到桌子上。 2、第二步, 我从牌顶再拿一张牌, 放在手上牌的底部。 3、第三步, 重复第一步、第二步的操作, 直到我手中所有的牌都放到了桌子上。 最后, 观众可以看到桌子上牌的顺序是:(牌底部)1,2,3,4,5,
阅读全文
摘要:春招的时候已经总结过这三个复杂的排序算法了,但是,当时还是有些不解,关于排序算法,冒泡,直接插入,简单选择都是很简单的,只要了解思想就可以写出来。 这三个算是比较复杂的了。(代码已测) (一)快排 快排考的是最多次的。之前看大神写的算法很简单,思想也很好。就一直用他的思想去思考快排了。 就是挖坑法。
阅读全文
摘要:Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2]. Note: Each element
阅读全文
摘要:137. Single Number II 137. Single Number II Total Accepted: 87688 Total Submissions: 229128 Difficulty: Medium Given an array of integers, every eleme
阅读全文
摘要:Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements
阅读全文
摘要:Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that duplicates do not exist in the tree. Subscribe to
阅读全文
摘要:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. The same repeat
阅读全文
摘要:The Trips table holds all taxi trips. Each trip has a unique Id, while Client_Id and Driver_Id are both foreign keys to the Users_Id at the Users tabl
阅读全文
摘要: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,
阅读全文
摘要:Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below a...
阅读全文
摘要:Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 val2) return 1;20 if(val1<val2) return -1;...
阅读全文
摘要:Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].首先题意理...
阅读全文
摘要:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 ->...
阅读全文
摘要:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes...
阅读全文
摘要: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"].Credits...
阅读全文
摘要:Description:Count the number of prime numbers less than a non-negative number, n.Credits:Special thanks to @mithmatt for adding this problem and creat...
阅读全文
摘要:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font ...
阅读全文
摘要:Example1: x = 123, return 321Example2: x = -123, return -321 click to show spoilers.Have you thought about this?Here are some good questions to ask be...
阅读全文
摘要:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Subscribe to see which com...
阅读全文
摘要: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->...
阅读全文