5/23/20
第二次打周赛。全部通过AC。纪念一下。最后一题DP用的不是最优解,写了2次bug version。
可以去Github直接看我其他leetcode代码。

  1. Q1455_Check If a Word Occurs As a Prefix of Any Word in a Sentence
class Solution {public int isPrefixOfWord(String sentence, String searchWord) {sentence = sentence.trim();if (sentence.isEmpty())return -1;String[] arr = sentence.split("\\s+");for (int i = 0; i < arr.length; i++) {if (arr[i].indexOf(searchWord) == 0)return i+1;}return -1;}
}
  1. Q1456_Maximum Number of Vowels in a Substring of Given Length
class Solution {public int maxVowels(String s, int k) {int n = s.length();boolean[] isVow = new boolean[n];int res = 0;for (int i = 0; i < n; i++) {if (s.charAt(i) == 'a' ||s.charAt(i) == 'e' ||s.charAt(i) == 'i' ||s.charAt(i) == 'o' ||s.charAt(i) == 'u')isVow[i] = true;if (i < k && isVow[i]) res++;}if (n < k)return res;int[] cnt = new int[n-k+1];cnt[0] = res;for (int i = 1; i < n-k+1; i++) {cnt[i] = cnt[i-1];if (isVow[i-1])cnt[i]--;if (isVow[i+k-1])cnt[i]++;if (cnt[i] > res)res = cnt[i];}return res;}
}
  1. Q1457_Pseudo-Palindromic Paths in a Binary Tree
class Solution {int res = 0;public int pseudoPalindromicPaths (TreeNode root) {preOrder(root, new int[10]);return res;}private void preOrder(TreeNode root, int[] cnt) {if (root == null)return;int val = root.val;cnt[val]++;if (root.left == null && root.right == null) {if (valid(cnt))res++;cnt[val]--;return;}preOrder(root.left, cnt);preOrder(root.right, cnt);cnt[val]--;}private boolean valid(int[] cnt) {int odd = 0;for (int i = 1; i <= 9; i++) {if (cnt[i] % 2 == 1)odd++;if (odd >= 2)return false;}return true;}
}
  1. Q1458_Max Dot Product of Two Subsequences
class Solution {public int maxDotProduct(int[] nums1, int[] nums2) {int res = Integer.MIN_VALUE;int m = nums1.length;int n = nums2.length;int[][] prod = new int[m][n];for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {prod[i][j] = nums1[i] * nums2[j];}}int len = Math.min(m, n);// first i elements in nums1, first j elements in nums2, used elements: kint[][][] dp = new int[m+1][n+1][len+1];for (int i = 1; i <= m; i++)for (int j = 1; j <= n; j++)for (int k = 1; k <= len; k++)dp[i][j][k] = Integer.MIN_VALUE;for (int i = 1; i <= m; i++) {for (int j = 1; j <= n; j++) {for (int k = 1; k <= Math.min(i,j); k++) {if (i > 1) dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j][k]);if (j > 1) dp[i][j][k] = Math.max(dp[i][j][k], dp[i][j-1][k]);dp[i][j][k] = Math.max(dp[i][j][k], dp[i-1][j-1][k-1] + prod[i-1][j-1]);}}}for (int k = 1; k <= len; k++)res = Math.max(res, dp[m][n][k]);return res;}
}

LeetCode weekly contest 190 周赛相关推荐

  1. LeetCode Weekly Contest 25 之 545.Boundary of Binary Tree

    LeetCode Weekly Contest 25 赛题 本次周赛主要分为以下4道题: 507 Perfect Number (3分) 537 Complex Number Multiplicati ...

  2. LeetCode——Weekly Contest 314

    LeetCode周赛第314场记录 2432. 处理用时最长的那个任务的员工 周赛第一题,根据题意写出代码即可.首先根据logs计算出每项工作的实际用时,然后根据用时长短对员工的ID号进行排序即可.给 ...

  3. LeetCode Weekly Contest 185

    5388. 重新格式化字符串 给你一个混合了数字和字母的字符串 s,其中的字母均为小写英文字母. 请你将该字符串重新格式化,使得任意两个相邻字符的类型都不同.也就是说,字母后面应该跟着数字,而数字后面 ...

  4. LeetCode Weekly Contest 199

    5472. 重新排列字符串 题目难度Easy 给你一个字符串 s 和一个 长度相同 的整数数组 indices . 请你重新排列字符串 s ,其中第 i 个字符需要移动到 indices[i] 指示的 ...

  5. LeetCode Weekly Contest 194

    1486. 数组异或操作 给你两个整数,n 和 start . 数组 nums 定义为:nums[i] = start + 2*i(下标从 0 开始)且 n == nums.length . 请返回 ...

  6. LeetCode Weekly Contest 27

    Reverse Words in a String III 简单暴力翻转 class Solution { public:string rev(string s){int len=s.length() ...

  7. LeetCode Weekly Contest 142

    又是两道题目,感觉rank要掉了呀~ 第一道看错题目了,然后浪费了很长时间,第三道很简单,思路也有,但是没时间了. 1093. Statistics from a Large Sample We sa ...

  8. LeetCode第187场周赛(Weekly Contest 187)解题报告

    差点又要掉分了,还好最后几分钟的时候,绝杀 AK.干巴爹!!! 第一题:思路 + 模拟暴力. 第二题:线性扫描. 第三题:双指针(滑动窗口) + 优先队列. 第四题:暴力每一行最小 k 个 + 优先队 ...

  9. 记LeetCode第143次周赛(Weekly Contest 143)

    上午打完LeetCode第143次周赛,发现很多不常用的知识点都比较生涩了,最后一个半小时也只ac了前两题.这一次的题目相对以往还是比较简单吧,但奈何就是迟迟没有在代码上有较满意的实现.学习果然是不进 ...

最新文章

  1. 冲上热搜的这款国产“阿法狗”,究竟是什么来头?
  2. 浅谈hashcode
  3. 【Paper】2021_Optimal Distributed Leader-following Consensus of Linear Multi-agent Systems: A Dynamic
  4. .NET疯狂架构经验分享系列之(七)WCF支持(转)
  5. MDM9x35MDM9x35启动流程简介
  6. 一个设计元素很多的网站
  7. mysql表的视图怎么建立_MySQL如何创建视图
  8. 搜索引擎提交注意事项
  9. Mapgis6.7 林相图自动注记 .
  10. predicate 列存储索引扫描_ColumnStore index (列存储索引)解析
  11. 【渝粤教育】电大中专幼儿园课程论 (10)作业 题库
  12. 如何基于MindSpore实现万亿级参数模型算法?
  13. STM32 Flash详解
  14. npm ERR! code E404 npm ERR! 404 Not Found - GET https://registry.npmjs.com/@mlamp%2fuser-info-dropdo
  15. 好用!一键生成数据库文档,这个开源的文档生成工具值得了解
  16. 如何组合来自多个SQL表的结果(提示:有三种方式)
  17. ffmpeg将sdp转发_ffmpeg常用命令
  18. php变量值传递,PHP将值传递到包含文件中的变量
  19. 【Java笔记】IO流(2):字符流
  20. IOCP实现聊天服务

热门文章

  1. 互联网秒杀设计--转载
  2. ubuntu16配置ZooKeeper集群(这里用的是Zookeeper3.4.10)
  3. 【Android源码】AlertDialog 源码分析
  4. 在laravel视图中直接使用{{ csrf_token() }}被翻译成英文显示的处理方法
  5. NVL 和NVL2函数
  6. SVN使用_获取某版本后改动的文件列表
  7. 【转】web 前端研发工程师编程能力飞升之路
  8. java泛型 简书_一文带你认识Java泛型基础
  9. 1.2.3 TCP/IP参考模型和五层参考模型
  10. SPI、UART、I2C三种串行总线简介