首页 > TAG信息列表 > sArr

159. Longest Substring with At Most Two Distinct Characters

Given a string s , find the length of the longest substring t  that contains at most 2 distinct characters. Example 1: Input: "eceba" Output: 3 Explanation: tis "ece" which its length is 3. Example 2: Input: "ccaabbb" Output

c++字符串

#include <stdio.h> #include <string.h> #include <iostream> using namespace std; /* 1, C语言中字符用单引号,字符串用双引号 由于C语言中没有真正的字符串类型,可以通过字符数组表示字符串,因为它的元素地址是连续的,这就足够了 C语言中字符串的表示: 一是定

【力扣每日一题】917. 仅仅反转字母

题目 给你一个字符串 s ,根据下述规则反转字符串: 所有非英文字母保留在原有位置。所有英文字母(小写或大写)位置反转。 返回反转后的 s 。 地址:https://leetcode-cn.com/problems/reverse-only-letters/ 题解 解题思路 字符串,对撞指针,具体定义可看https://blog.csdn.net/Atalant

76. 最小覆盖子串

class Solution { public String minWindow(String s, String t) { // 创建要覆盖的字符串数组,容量为ASCII值的数量 int[] tArr = new int[256]; int tLen = t.length(); int sLen = s.length(); for(int i = 0;i < tLen;i++)

Leetcode 557. 反转字符串中的单词 III c#

给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序。 示例: 输入:“Let’s take LeetCode contest” 输出:“s’teL ekat edoCteeL tsetnoc” 提示: 在字符串中,每个单词由单个空格分隔,并且字符串中不会有任何额外的空格。 public string Rever

Cookie加密处理

[Cookie加密处理] 在保存用户信息阶段,主要的工作是对用户的信息进行加密并保存到客户端。加密用户的信息是较为繁琐的,大致上可分为以下几个步聚: ① 得到用户名、经MD5加密后的用户密码、cookie有效时间(本文设置的是两星期,可根据自己需要修改) ② 自定义的一个webKey,这个

LeetCode 159 Longest Substring with At Most Two Distinct Characters

Given a string s , find the length of the longest substring t  that contains at most 2 distinct characters. Example 1: Input: "eceba" Output: 3 Explanation: tis "ece" which its length is 3. Example 2: Input: "ccaabbb" Output

340. Longest Substring with At Most K Distinct Characters

把上题的2换成k即可 public int lengthOfLongestSubstringKDistinct(String s, int k) { if (s == null || s.length() == 0 || k == 0) { return 0; } char[] sArr = s.toCharArray(); int[] hash = new int[256]; int l = 0, co

leecode-找出其中不含有重复字符的 最长子串 的长度

给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。这道题主要用到思路是:滑动窗口class Solution { /** * @param String $s * @return Integer */ function lengthOfLongestSubstring($s) { $len = strlen($s); $sarr = str_split($s,1);

LeetCode4:寻找两个有序数组的中位数

这个题目真的抽象 题目描述 给定两个大小为 m 和 n 的有序数组 nums1 和 nums2。 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n))。 你可以假设 nums1 和 nums2 不会同时为空。 中位数需要满足两个条件: 1.左侧和右侧数量相等 2.比左侧数的最大值