随笔分类 -  算法&Leetcode

摘要:我手中有一堆扑克牌, 但是观众不知道它的顺序。 1、第一步, 我从牌顶拿出一张牌, 放到桌子上。 2、第二步, 我从牌顶再拿一张牌, 放在手上牌的底部。 3、第三步, 重复第一步、第二步的操作, 直到我手中所有的牌都放到了桌子上。 最后, 观众可以看到桌子上牌的顺序是:(牌底部)1,2,3,4,5, 阅读全文
posted @ 2020-09-02 17:21 0giant 阅读(497) 评论(0) 推荐(1) 编辑
摘要:春招的时候已经总结过这三个复杂的排序算法了,但是,当时还是有些不解,关于排序算法,冒泡,直接插入,简单选择都是很简单的,只要了解思想就可以写出来。 这三个算是比较复杂的了。(代码已测) (一)快排 快排考的是最多次的。之前看大神写的算法很简单,思想也很好。就一直用他的思想去思考快排了。 就是挖坑法。 阅读全文
posted @ 2016-08-23 10:07 0giant 阅读(2130) 评论(0) 推荐(1) 编辑
摘要: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 阅读全文
posted @ 2016-07-03 11:09 0giant 阅读(347) 评论(0) 推荐(0) 编辑
摘要:137. Single Number II 137. Single Number II Total Accepted: 87688 Total Submissions: 229128 Difficulty: Medium Given an array of integers, every eleme 阅读全文
posted @ 2016-06-28 15:08 0giant 阅读(339) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2016-06-28 10:33 0giant 阅读(302) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2016-06-25 21:39 0giant 阅读(163) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2016-06-15 12:17 0giant 阅读(269) 评论(0) 推荐(0) 编辑
摘要: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 阅读全文
posted @ 2016-05-24 11:02 0giant 阅读(732) 评论(0) 推荐(0) 编辑
摘要: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, 阅读全文
posted @ 2016-03-28 10:52 0giant 阅读(196) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2016-01-05 17:20 0giant 阅读(271) 评论(0) 推荐(0) 编辑
摘要:Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 val2) return 1;20 if(val1<val2) return -1;... 阅读全文
posted @ 2016-01-04 23:04 0giant 阅读(208) 评论(0) 推荐(0) 编辑
摘要: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].首先题意理... 阅读全文
posted @ 2016-01-04 17:30 0giant 阅读(153) 评论(0) 推荐(0) 编辑
摘要:Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 ->... 阅读全文
posted @ 2016-01-04 16:19 0giant 阅读(142) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2016-01-04 14:24 0giant 阅读(181) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2016-01-04 10:53 0giant 阅读(331) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2015-12-30 10:49 0giant 阅读(266) 评论(0) 推荐(0) 编辑
摘要: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 ... 阅读全文
posted @ 2015-12-28 09:42 0giant 阅读(253) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2015-12-24 16:09 0giant 阅读(195) 评论(0) 推荐(0) 编辑
摘要: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... 阅读全文
posted @ 2015-12-24 14:15 0giant 阅读(162) 评论(0) 推荐(0) 编辑
摘要: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->... 阅读全文
posted @ 2015-12-24 10:55 0giant 阅读(243) 评论(0) 推荐(0) 编辑