2018年1月29日

leetcode 189. Rotate Array

摘要: 前进k步,k可能大于数组。 。。。 阅读全文

posted @ 2018-01-29 23:22 willaty 阅读(90) 评论(0) 推荐(0) 编辑

leetcode 183. Customers Who Never Order

摘要: select Name as Customers from Customers where Id not in (select CustomerId from Orders); 阅读全文

posted @ 2018-01-29 23:11 willaty 阅读(82) 评论(0) 推荐(0) 编辑

leetcode 182. Duplicate Emails

摘要: 找出重复的数据。 阅读全文

posted @ 2018-01-29 23:08 willaty 阅读(102) 评论(0) 推荐(0) 编辑

leetcode 181. Employees Earning More Than Their Managers

摘要: 直接写也行 阅读全文

posted @ 2018-01-29 23:01 willaty 阅读(108) 评论(0) 推荐(0) 编辑

leetcode 176. Second Highest Salary

摘要: 查询第二大的数。 阅读全文

posted @ 2018-01-29 22:44 willaty 阅读(142) 评论(0) 推荐(0) 编辑

leetcdoe 175. Combine Two Tables

摘要: 给定两个表,一个是人,一个是地址,要求查询所有人,可以没有地址。 详细可参考:https://www.cnblogs.com/grandyang/p/5348900.html 阅读全文

posted @ 2018-01-29 22:26 willaty 阅读(283) 评论(0) 推荐(0) 编辑

leetcode 172. Factorial Trailing Zeroes

摘要: 求阶乘的尾0,要求对数时间复杂度。 解决: 只有2*5能得出0,对于阶乘,各项因子,因子2的数量肯定大于5,求5即可。 含有5的因子有5,25... 阅读全文

posted @ 2018-01-29 22:09 willaty 阅读(119) 评论(0) 推荐(0) 编辑

leetcode 171. Excel Sheet Column Number

摘要: 给定字符串,A-Z代表1~26,转化为数字,AA表示27。 阅读全文

posted @ 2018-01-29 22:07 willaty 阅读(101) 评论(0) 推荐(0) 编辑

leetcode 169. Majority Element

摘要: 给定一个数组,其中一个数字出现的次数超过整个数组的一半,求这个数字。数组非空且必有解。 解法有二: 哈希: 把map改为unordered_map即为哈希,但更慢:-(,肯定是测试集里有数字比较大,坑。 摩尔投票算法: 未完待续。。。 可参考: http://blog.csdn.net/u01250 阅读全文

posted @ 2018-01-29 18:17 willaty 阅读(116) 评论(0) 推荐(0) 编辑

leetcode 168. Excel Sheet Column Title

摘要: 将数字转化为字母,如1 - A, 26 - Z, 27 - 27。 解决: 理解辗转相除法即可,思考: Z*26^2 + Z*26^1 + Z*26^0 辗转相除,除以26的时候,Z*26^1 + Z*26^0 + (Z / 26),最后多个1。要么减掉,要么判断。 也可先--n再除,直接加上‘A’ 阅读全文

posted @ 2018-01-29 15:45 willaty 阅读(106) 评论(0) 推荐(0) 编辑

leetcode 167 Two Sum II - Input array is sorted

摘要: 给定一个有序的数组,和一个整数目标,求两个数的和等于目标的索引,索引从1开始。假设必定存在解。 有两种思路: 直接找: 原理显而易见,最坏情况,也就O(n),当两个索引位于中间位置。 二分查找: 每次都是二分地前进后退,最坏情况下达到O(nlogn),当两索引位于中间。 但当两个答案靠近某一端时性能 阅读全文

posted @ 2018-01-29 13:08 willaty 阅读(129) 评论(0) 推荐(0) 编辑

leetcode 155 Min Stack

摘要: 设计一个最小栈,要求push,pop,top,getMin都是O(1)的。 关键在于: 维护一个普通栈的同时,维护额外一个栈,保存正常栈的递减序列。即除了第一元素,之后的元素都比最小栈的top小。 原理想想就懂,只有更小的能成为min。注意相同元素也入最小栈就行。 阅读全文

posted @ 2018-01-29 11:04 willaty 阅读(76) 评论(0) 推荐(0) 编辑

导航