ICode9

精准搜索请尝试: 精确搜索
  • 蓝桥杯—删除字符(java实现)2022-03-02 23:02:42

    import java.util.Scanner; // 1:无需package // 2: 类名必须Main, 不可修改 public class Main {     public static void main(String[] args) {         Scanner scan = new Scanner(System.in);         //在此输入您的代码...  

  • #1048 Longest String Chain2022-03-01 10:59:06

    Description You are given an array of words where each word consists of lowercase English letters. wordA is a predecessor of wordB if and only if we can insert exactly one letter anywhere in wordA without changing the order of the other characters to mak

  • LeetCode 0010 Regular Expression Matching2022-02-27 08:00:34

    原题传送门 1. 题目描述 2. Solution 1 1、思路分析 I. 状态定义 f[i][j] = s的前i个字符与p中的前j个字符是否能够匹配。 ​ II. 初始状态 f[0][0] = true,即两个空字符串是可以匹配的。 ​ III. 状态转移方程 对于匹配情况的讨论 若p[j]是小写字母,则必须在s中匹配一个相同的字

  • LeetCode 0008 String to Integer (atoi)2022-02-25 08:33:07

    原题传送门 1. 题目描述 2. Solution 1 1、思路分析 自动状态机 a.) 输入字符所有可能情况分类: space(空格), +/-, number, other b.) 根据当前状态(字符),与下一个字符可以得出下一状态: 即 下一状态 = f(当前状态, 下一字符) 下一字符 space +/- number

  • 不含重复字符的最长子串2022-02-19 21:02:54

    不含重复字符的最长子串: 代码实现 public int longestSubStr(String str) { int max = 0; Deque<Character> deque = new ArrayDeque<>(); for (int i = 0; i < str.length(); i++) { if (!deque.contains(str.charAt(i))) {

  • 686--重复叠加字符串匹配(总结技巧)2022-02-16 18:02:51

    题目 给定两个字符串 a 和 b,寻找重复叠加字符串 a 的最小次数,使得字符串 b 成为叠加后的字符串 a 的子串,如果不存在则返回 -1。 注意:字符串 "abc" 重复叠加 0 次是 "",重复叠加 1 次是 "abc",重复叠加 2 次是 "abcabc"。 解答 package Com.Xu.String; public class SixEightSix

  • kmp解决字符串算法2022-02-15 11:03:40

    package com.zou.Algorithm.kmp;import java.util.Arrays;public class KmpAlgorithm { public static void main(String[] args) { String str1="BBC ABCDAB ABCDABCDABDE"; String str2="ABCDABD"; int[] next=kmpNext("A

  • KMP算法2022-02-11 11:02:45

    KMP的主要思想是当出现字符串不匹配时,可以知道一部分之前以及匹配的文本内容,可以利用这些信息避免从头再去做匹配。如何记录已经匹配的文本内容,是KMP的重点,也是next数组肩负的重任。 这个next数组为前缀表,代表的是模式串中当前位置及其之前的子串相同前后缀的长度的最大值。(这里

  • leetcode242_有效的字母异位词2022-02-10 22:33:07

    class Solution { public boolean isAnagram(String s, String t) { if (s.length() != t.length()) { return false; } int[] table = new int[26]; for (int i = 0; i < s.length(); i++) { table[s.charAt

  • 9. 回文数2022-02-10 21:00:48

    1 public static void isPalindrome() { 2 int a = 1122111; 3 //Integer integer = new Integer(a); 4 //自动装箱 5 Integer integer = a; 6 String str = integer.toString(); 7 int strLength = str.length(); 8

  • 正则表达式匹配-动态规划2022-02-09 15:59:26

    题目 给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 ‘.’ 和 ‘’ 的正则表达式匹配。 ‘.’ 匹配任意单个字符 '’ 匹配零个或多个前面的那一个元素 示例 输入:s = “aa” p = “a” 输出:false 解释:“a” 无法匹配 “aa” 整个字符串。 算法 dp[i][j]下标从1到

  • 2022-02-07(301. 删除无效的括号)2022-02-08 15:01:25

    class Solution { public List<String> removeInvalidParentheses(String s) { List<String> ans = new ArrayList<String>(); Set<String> currSet = new HashSet<String>(); currSet.add(s); while (tr

  • 【蓝桥杯】回文日期2022-02-07 16:02:12

    import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; /* * 回文时间 */ public class Main { public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub Scanner in = new Scanner(System.in);

  • leetcode刷题题解——20. 有效的括号2022-02-06 19:34:53

    很久之前做的答案 public boolean isValid(String s) { char[] c = new char[10000]; int j=0; for(int i=0;i<s.length();i++){ switch(c[j]){ case '(': if(s.charAt(i)==')') j--

  • Leetcode 刷题笔记(八) —— 字符串篇之 KMP2022-02-05 15:01:09

    KMP 什么是 KMP 算法?next 数组题录28. 实现 strStr()459. 重复的子字符串 刷题路线以及 KMP 详解 :代码随想录 什么是 KMP 算法? KMP 是以 3 位发明者名字的首字母命名的,常用来字符串匹配上。如:判断 s1 是不是 s2 的子串,KMP 算法将解决此问题的时间复杂度从 O(m*n) 降低

  • 408. Valid Word Abbreviation2022-02-04 03:31:23

    This is two points problem, just concentrate and carefully deal with the characters, then the problem can be solved. This is a very good problem for writing all kinds of edge test cases. public boolean validWordAbbreviation(String word, String abbr)

  • 1216. Valid Palindrome III2022-02-03 01:00:20

    This is the typical DP problem, the time complexity is O(n2), Where n is the length of string s. This is due to the fact that we try to find result for all combinations of l and r where l and r range from 0 to n: private int[][] visited; p

  • leetcode刷题——无重复字符最长子串(Java)2022-01-31 19:32:56

    1.题目 2.条件与思路 利用双指针 3.解题过程 class Solution { public int lengthOfLongestSubstring(String s) { int len = s.length(); boolean flag = true; List l = new ArrayList(); for(int i=0;i<len;i++){ char

  • LeetCode 2047. 句子中的有效单词数2022-01-27 21:02:53

    2047. 句子中的有效单词数 Solution 思路:简单模拟题,首先将单词划分开,然后根据条件一个一个否定即可。标记连接符和标点符号的位置,进行判断,这里注意特判是在数值为1的时候做的。 class Solution { public int countValidWords(String sentence) { String[] words = sen

  • Longest Common Substring (K3)2022-01-25 08:32:47

    原题在这里: https://leetcode.com/discuss/interview-question/1273766/longest-common-substring 这道题跟https://www.cnblogs.com/feiflytech/p/15841611.html 类似,但是不完全相同: 首选自顶向下写个递归,与1143只有一点点不同。 private Integer[][] dp; private int m

  • 【每日编程08】拼写单词和一年中的第几天2022-01-24 22:01:02

    题目1: 拼写单词 解题思路: 使用哈希表存储chars中每个字母的数量 再使用一个哈希表存储word中每个字母的数量 将这两个哈希表的键值对逐一进行比较 //先来一个比较通俗易懂的代码 class Solution{ public int countCharacters(String[] words, String chars){

  • 代码随想录刷题-字符串2022-01-23 23:59:37

    本文是每天跟着代码随想录刷题时做的笔记,用来总结与复习。 目录 344.反转字符串 541.反转字符串Ⅱ 剑指offer 05.替换空格 151.反转字符串里的单词 剑指offer 58-Ⅱ.左旋转字符串 28.实现strStr() 459.重复的子字符串 今日总结 344.反转字符串 题目链接:344. 反转字符串 - 力

  • JAVA 遍历字符串方法charAt()2022-01-22 18:02:13

    String类中的public char charAt(int index)方法 返回索引处的char值 使用for循环遍历输出字符串 package Experience; import java.util.Scanner; public class iterateString { public static void main(String args[]){ Scanner str=new Scanner(System.in);

  • LeetCode 1332. 删除回文子序列2022-01-22 11:34:15

    1332. 删除回文子序列 Solution 思路: 回文子序列 所以最多两次,如果一开始就是回文串的话 就是一次。 class Solution { public int removePalindromeSub(String s) { int i =0, j = s.length() - 1; while (i < j) { if (s.charAt(i) == s.charAt

  • 面试题19. 正则表达式匹配2022-01-21 10:33:33

    请实现一个函数用来匹配包含'. '和''的正则表达式。模式中的字符'.'表示任意一个字符,而''表示它前面的字符可以出现任意次(含0次)。在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串"aaa"与模式"a.a"和"abaca"匹配,但与"aa.a"和"ab*a"均不匹配。 来源:力扣(LeetCode) 链接:ht

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有