随笔分类 -  problems

上一页 1 2 3 4 5 6 下一页

leetcode 225. Implement Stack using Queues
摘要:可以用两个队列倒来倒去,保留最后一个,pop效率成了线性的。 我这里用一个队列,自己倒自己,pop和top都是线性,时间换空间吧。 阅读全文

posted @ 2018-02-06 11:23 willaty 阅读(91) 评论(0) 推荐(0)

leetcode 219. Contains Duplicate II
摘要:哈希,注意第一个为0的情况。 阅读全文

posted @ 2018-02-06 11:01 willaty 阅读(89) 评论(0) 推荐(0)

leetcode 217. Contains Duplicate
摘要:哈希一下即可。 阅读全文

posted @ 2018-02-06 09:58 willaty 阅读(80) 评论(0) 推荐(0)

leetcode 206. Reverse Linked List
摘要:头插法,每次取出后插入新链表的头部。 阅读全文

posted @ 2018-02-06 09:49 willaty 阅读(70) 评论(0) 推荐(0)

leetcode 627. Swap Salary
摘要:将f改为m,m改为f。 注意: case在select后面,group by,update等地方都可以使用。 阅读全文

posted @ 2018-02-01 14:32 willaty 阅读(316) 评论(0) 推荐(0)

leetcode 197. Rising Temperature
摘要:查询今天比前一天温度低的Id。 阅读全文

posted @ 2018-01-31 19:49 willaty 阅读(113) 评论(0) 推荐(0)

leetcode 196. Delete Duplicate Emails
摘要:# 慢,内连接delete p1 from Person p1, Person p2 where p1.Email=p2.Email and p1.Id>p2.Id delete from Person where Id not in ( select Id from ( select min(Id) as Id from Person group by... 阅读全文

posted @ 2018-01-31 10:45 willaty 阅读(122) 评论(0) 推荐(0)

leetcode 205. Isomorphic Strings
摘要:求两字符串是否同构。即每个字符可且仅可映射为一个字符(包括自己),若两字符串经过某映射相同,则同构。 朴素的解法是保存其映射值和被映射值。 其实只要保存布尔值即可,巧妙。 阅读全文

posted @ 2018-01-30 14:22 willaty 阅读(83) 评论(0) 推荐(0)

leetcode 203. Remove Linked List Elements
摘要:删除链表中某个元素。 要么直接删,要么值覆盖。算法题就不用free了。 阅读全文

posted @ 2018-01-30 14:13 willaty 阅读(85) 评论(0) 推荐(0)

leetcode 202. Happy Number
摘要:一个数,是否为happy number,取每一位求平方和,得出结果继续,如果结果为1则为happy number。 阅读全文

posted @ 2018-01-30 13:05 willaty 阅读(126) 评论(0) 推荐(0)

leetcode 198. House Robber
摘要:给定一系列整数,取整数,相邻不能取。 解法有二: 动态规划: 求差: 取last = nk - n(k - 1) + n(k - 2) - n(k - 3)...,当遍历到当前元素时,做差,如果结果为正数,则取;否则置0(相当于断开)。 而上式和sum求和除二等于相邻元素和。 阅读全文

posted @ 2018-01-30 13:04 willaty 阅读(127) 评论(0) 推荐(0)

leetcode 191. Number of 1 Bits
摘要:统计bit中1的个数。与一下即可。 阅读全文

posted @ 2018-01-30 10:49 willaty 阅读(113) 评论(0) 推荐(0)

leetcode 190. Reverse Bits
摘要:将32位反转。 也可以用bitset。 阅读全文

posted @ 2018-01-30 00:30 willaty 阅读(93) 评论(0) 推荐(0)

leetcode 189. Rotate Array
摘要:前进k步,k可能大于数组。 。。。 阅读全文

posted @ 2018-01-29 23:22 willaty 阅读(92) 评论(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 阅读(86) 评论(0) 推荐(0)

leetcode 182. Duplicate Emails
摘要:找出重复的数据。 阅读全文

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

leetcode 181. Employees Earning More Than Their Managers
摘要:直接写也行 阅读全文

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

leetcode 176. Second Highest Salary
摘要:查询第二大的数。 阅读全文

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

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

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

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

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

上一页 1 2 3 4 5 6 下一页

导航