[Locked] Paint House I & II】的更多相关文章

Paint House There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses…
Paint House There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses…
Paint Fence There is a fence with n posts, each post can be painted with one of the k colors. You have to paint all the posts such that no more than two adjacent fence posts have the same color. Return the total number of ways you can paint the fence…
Meeting Room Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings. For example,Given [[0, 30],[5, 10],[15, 20]],return false. 分析: 即判断这些区间是否有重叠,遍历一遍…
Flip Game I You are playing the following Flip Game with your friend: Given a string that contains only these two characters:+and -, you and your friend take turns to flip two consecutive "++" into "--". The game ends when a person can…
Palindrome Permutation I Given a string, determine if a permutation of the string could form a palindrome. For example,"code" -> False, "aab" -> True, "carerac" -> True. Hint: Consider the palindromes of odd vs even…
Paint House I/II 要点:这题要区分房子编号i和颜色编号k:目标是某个颜色,所以min的list是上一个房子编号中所有其他颜色+当前颜色的cost https://repl.it/Chwe/1 (I) 善用slicing来eliminate list中一点,还有一点好处是不用考虑超越边界了 II:如何从O(nkk)降到O(n*k)? 每次找到上一个房子编号list的的min这个循环如果在每个k都做一遍,肯定是redundant的.其实loop一遍就能找到对所有颜色k需要的min:m…
sql语句优化总结 数据库优化的几个原则: 1.尽量避免在列上做运算,这样会导致索引失败: 2.使用join是应该用小结果集驱动大结果集,同时把复杂的join查询拆分成多个query.不然join的越多表,就会导致越多的锁定和堵塞. 3.注意like模糊查询的使用,避免使用%%,例如select * from a where name like '%de%'; 代替语句:select * from a where name >= 'de' and name < 'df'; 4.仅列出需要查询的…
There are a row of n houses, each house can be painted with one of the k colors. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color. The cost of pai…
House Robber:不能相邻,求能获得的最大值 House Robber II:不能相邻且第一个和最后一个不能同时取,求能获得的最大值 House Robber III:二叉树下的不能相邻,求能获得的最大值 Paint House:用3种颜色,相邻的房屋不能用同一种颜色,求花费最小 Paint House II:用k种颜色,相邻的房屋不能用同一种颜色,求花费最小Paint Fence:用k种颜色,相邻的可以用同一种颜色,但不能超过连续的2个,求有多少种可能性 198. House Robb…