publicintshoppingOffers(List<Integer> price_, List<List<Integer>> special_, List<Integer> needs){ price = price_; special = special_; cache = new HashMap<>(); return dfs(needs); }
privateintdfs(List<Integer> needs){ int ans = 0; StringBuilder sb = new StringBuilder(); for(int i=0;i<needs.size();i++){ ans += price.get(i) * needs.get(i); sb.append(needs.get(i) + "#"); } if(ans != 0){ String key = sb.toString(); if(cache.containsKey(key)){ ans = cache.get(key); }else{ for(List<Integer> sp: special){ boolean check = true; for(int i=0;i<needs.size();i++) if(sp.get(i) > needs.get(i)){ check = false; break; } if(check){ List<Integer> next = new ArrayList<>(); for(int i=0;i<needs.size();i++){ next.add(needs.get(i) - sp.get(i)); } ans = Math.min(ans, dfs(next) + sp.get(sp.size()-1)); } } cache.put(key, ans); } } return ans; } }
键盘行
# T500 键盘行 classSolution{ public String[] findWords(String[] words) { List<String> list = new ArrayList<String>(); String rowIdx = "12210111011122000010020202"; for (String word : words) { boolean isValid = true; char idx = rowIdx.charAt(Character.toLowerCase(word.charAt(0)) - 'a'); for (int i = 1; i < word.length(); ++i) { if (rowIdx.charAt(Character.toLowerCase(word.charAt(i)) - 'a') != idx) { isValid = false; break; } } if (isValid) { list.add(word); } } String[] ans = new String[list.size()]; for (int i = 0; i < list.size(); ++i) { ans[i] = list.get(i); } return ans; } }
整数除法
# 剑指 Offer II 001. 整数除法 classSolution{ publicintdivide(int a, int b){ if(a==0x80000000 && b==-1){ return Integer.MAX_VALUE; } int negative = 2; if (a>0){ negative--; a = -a; } if(b>0){ negative--; b=-b; }
int result = divideCore(a,b); return negative==1? -result : result; }
privateintdivideCore(int a, int b){ int result=0; while(a<=b){ int value = b; int quotient = 1; while(value>=0x80000000 && a<=value+value){ quotient+=quotient; value+=value; }
result +=quotient; a-=value; } return result; } }
二进制加法
classSolution{ public String addBinary(String a, String b){ StringBuilder result = new StringBuilder(); int i = a.length() - 1; int j = b.length() - 1; int carry = 0; while (i>=0 || j>=0){ int digitA = i >= 0 ? a.charAt(i--) - '0' : 0; int digitB = j >= 0 ? b.charAt(j--) - '0' : 0; int sum = digitA + digitB + carry; carry = sum >= 2 ? 1 : 0; sum = sum >= 2? sum - 2 : sum; result.append(sum); }
# T175 组合两个表 # Write your MySQL query statement below select FirstName,LastName,City,State from Person leftjoin Address on Person.PersonId = Address.PersonId;
# 超过经理收入的员工 # Write your MySQL query statement below # where select a.Name as Employee from Employee AS a, Employee AS b where a.ManagerId = b.id and a.Salary > b.Salary;
# Join select a.Name as Employee from Employee AS a join Employee AS b on a.ManagerId = b.id and a.Salary > b.Salary;
# 182 查找重复的电子邮箱 # Write your MySQL query statement below
select Email from ( select Email, count(Email) asnum from Person groupby Email ) as statistic wherenum > 1;
每个编写代码的人都有自己喜欢的语言。这种情况经常发生,因为我们学习了某种编程语言,或者我们很快掌握了它, 或者它使我们的工作变得更容易。 拥有首选语言有几个原因。然而,我们的语言有时可能会变得单调乏味。它不再由制造它的公司维护,或者人们出于 某种无法解释的原因停止使用它。 其他语言,例如 C,在许多情况下仍然是最流行的编程语言,经受住了时间的考验。 关键 是编程语言似乎有一个生命周期,对于某些人来说,末日似乎已经到来。 ————《5 Programming Languages that will Die》
Tip
sidekiq及数据库的一点技巧
显示db中所有进程
showprocesslist;
查询有无慢查询
select * from information_schema.processlist where Command != 'Sleep'and Time > 300orderbyTimedesc;
查询所有表的行数
SELECT table_name, table_rows FROM information_schema.tables WHERE table_schema = '******' ORDERBY table_rows desc;