例如,“abcabcbb”不具有重复字符的最长子串是“abc”,长度为3。对于“bbbbb”,最长的不具有重复字符的子串是“b”,长度为1。 Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc",...
Given a string, find the first non-repeating character in it and return it's index. If it doesn't exist, return -1. Examples: s = "leetcode" return 0. s = "loveleetcode", return 2. Note:You may assume the string contain only lowercase letters. 这道题确实没有什么难度,我们只要用...
Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1. Examples: AI检测代码解析 s = "leetcode" return 0. s = "loveleetcode", return 2. 1. 2. 3. 4. 5. 题意:给定一个字符串,返回字符串中第一个在字符串中只出现过...
LeetCode 387: 字符串中的第一个唯一字符 First Unique Character in a String 题目: 给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。 Given a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1....
像这道题就是总是考虑窗口左侧的 char 为 repeating char。 代码语言:javascript 代码运行次数:0 运行 复制 class Solution { public int characterReplacement(String s, int k) { if (s==null || k<0) throw new IllegalArgumentException(); if (s.length()==0) return 0; int left=0, right=0;...
Longest Repeating Character Replacement Leetcode 76. Minimum Window Substring Leetcode 3. Longest Substring Without Repeating Characters Leetcode 1004 Max Consecutive Ones III Leetcode 1658 Minimum Operations to Reduce X to Zero 宽度优先搜索(BFS):面试中最常考的 基础知识: 常见的BFS用来解决什么问题?
每次计算重复字母长度时,当出现更长的可能时,都更新最终的结果。 code 代码语言:javascript 代码运行次数:0 funccharacterReplacement(s string,k int)int{iflen(s)==0{return0}str:=[]byte(s)start,end:=0,0ret:=0c:=make([]int,26)c[str[0]-'A']++forlen(str)>end{maxc:=0fori:=0;i<26;...
描述:有一个手表,假设小时范围是0~11,分钟范围是0~59。如果时和分的二级制表示总共有N个1,求所有可能的时间。 //#401Description: Binary Watch | LeetCode OJ 解法1:水题。 // Solution 1: Easy. 代码1 //Code 1 402 Remove K Digits // #402 移除K个数字 ...
Shortest Distance to a Character Swift Easy O(n) O(1) Multiply Strings Swift Medium O(n) O(1) Palindrome Permutation Swift Easy O(n) O(n) Valid Anagram Swift Easy O(n) O(n) Ransom Note Swift Easy O(n) O(n) Group Anagrams Swift Medium O(nmlogm + nlogn) O(n) Find Duplicate...
3Longest Substring Without Repeating CharactersPythonJava1. Check every possible substring O(n^2) 2. Remember the character index and current check pos, if character index >= current pos, then there is duplicate 4Median of Two Sorted ArraysPythonJava1. Merge two sorted lists and compute median...