原文链接: https://leetcode-cn.com/problems/permutation-i-lcci 英文原文Write a method to compute all permutations of a string of unique characters. Example1: Input: S = "qwe" Output: ["qwe", "qew", "wqe", "weq", "ewq", "eqw"] Example2: Input: S = "ab" Output:…
标签详情
字符串 分类
原文链接: https://leetcode-cn.com/problems/sparse-array-search-lcci 英文原文Given a sorted array of strings that is interspersed with empty strings, write a method to find the location of a given string. Example1: Input: words = ["at", "", "", "", "ball", ""…
原文链接: https://leetcode-cn.com/problems/words-frequency-lcci 英文原文Design a method to find the frequency of occurrences of any given word in a book. What if we were running this algorithm multiple times? You should implement following methods: WordsFreq…
原文链接: https://leetcode-cn.com/problems/ti-huan-kong-ge-lcof 中文题目请实现一个函数,把字符串 s 中的每个空格替换成"%20"。 示例 1: 输入:s = "We are happy." 输出:"We%20are%20happy." 限制: 0 <= s 的长度 <= 10000 通过代码 高赞题解方法一:遍历添加在 Python 和 Java 等语言中,字符串都被设计成「不可变」的类型,即无法直接修改字符串的某一位字符,需要新建一个字…
原文链接: https://leetcode-cn.com/problems/biao-shi-shu-zhi-de-zi-fu-chuan-lcof 中文题目请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。 数值(按顺序)可以分成以下几个部分: 若干空格 一个 小数 或者 整数 (可选)一个 'e' 或 'E' ,后面跟着一个 整数 若干空格 小数(按顺序)可以分成以下几个部分: (可选)一个符号字符('+' 或 '-') 下述格式之一: 至少一位数字,后面跟着一个点 '.' 至少…
原文链接: https://leetcode-cn.com/problems/zheng-ze-biao-da-shi-pi-pei-lcof 中文题目请实现一个函数用来匹配包含'. '和'*'的正则表达式。模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(含0次)。在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串"aaa"与模式"a.a"和"ab*ac*a"匹配,但与"aa.a"和"ab*a"均不匹配。 示例 1: 输入: s = "aa" p = "a"…
原文链接: https://leetcode-cn.com/problems/xu-lie-hua-er-cha-shu-lcof 中文题目请实现两个函数,分别用来序列化和反序列化二叉树。 你需要设计一个算法来实现二叉树的序列化与反序列化。这里不限定你的序列 / 反序列化算法执行逻辑,你只需要保证一个二叉树可以被序列化为一个字符串并且将这个字符串反序列化为原始的树结构。 提示:输入输出格式与 LeetCode 目前使用的方式一致,详情请参阅 LeetCode 序列化二叉树的格式。你并非必须采取这…
原文链接: https://leetcode-cn.com/problems/zi-fu-chuan-de-pai-lie-lcof 中文题目输入一个字符串,打印出该字符串中字符的所有排列。 你可以以任意顺序返回这个字符串数组,但里面不能有重复元素。 示例: 输入:s = "abc" 输出:["abc","acb","bac","bca","cab","cba"] 限制: 1 <= s 的长度 <= 8 通过代码 高赞题解解题思路:对于一个长度为 $n$ 的字符串(假设字符互不重复),其排列方案…
原文链接: https://leetcode-cn.com/problems/di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof 中文题目在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 s 只包含小写字母。 示例 1: 输入:s = "abaccdeff" 输出:'b' 示例 2: 输入:s = "" 输出:' ' 限制: 0 <= s 的长度 <= 50000 通过代码 高赞题解本题考察 哈希表 的使用,本文介绍 哈希表 和 有序哈希表 …
原文链接: https://leetcode-cn.com/problems/ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof 中文题目输入一个非负整数数组,把数组里所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个。 示例 1: 输入: [10,2] 输出: "102" 示例 2: 输入: [3,30,34,5,9] 输出: "3033459" 提示: 0 < nums.length <= 100 说明: 输出结果可能非常大,所以你需要返回一个字符串…
原文链接: https://leetcode-cn.com/problems/fan-zhuan-dan-ci-shun-xu-lcof 中文题目输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变。为简单起见,标点符号和普通字母一样处理。例如输入字符串"I am a student. ",则输出"student. a am I"。 示例 1: 输入: "the sky is blue" 输出: "blue is sky the" 示例 2: 输入: " hello world! " …
原文链接: https://leetcode-cn.com/problems/zuo-xuan-zhuan-zi-fu-chuan-lcof 中文题目字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。请定义一个函数实现字符串左旋转操作的功能。比如,输入字符串"abcdefg"和数字2,该函数将返回左旋转两位得到的结果"cdefgab"。 示例 1: 输入: s = "abcdefg", k = 2 输出: "cdefgab" 示例 2: 输入: s = "lrloseumgh", …
原文链接: https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof 中文题目请从字符串中找出一个最长的不包含重复字符的子字符串,计算该最长子字符串的长度。 示例 1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。 示例 2: 输入: "bbbbb" 输出: 1 解释: 因为无重复字符的最长子串是 "b",所以其长度…
原文链接: https://leetcode-cn.com/problems/ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof 中文题目写一个函数 StrToInt,实现把字符串转换成整数这个功能。不能使用 atoi 或者其他类似的库函数。 首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止。 当我们寻找到的第一个非空字符为正或者负号时,则将该符号与之后面尽可能多的连续数字组合起来,作为该整数的正负号;假如第一个非空字符是数…
原文链接: https://leetcode-cn.com/problems/permutation-ii-lcci 英文原文Write a method to compute all permutations of a string whose characters are not necessarily unique. The list of permutations should not have duplicates. Example1: Input: S = "qqe" Output:…
原文链接: https://leetcode-cn.com/problems/master-mind-lcci 英文原文The Game of Master Mind is played as follows: The computer has four slots, and each slot will contain a ball that is red (R). yellow (Y). green (G) or blue (B). For example, the computer mig…
原文链接: https://leetcode-cn.com/problems/one-away-lcci 英文原文There are three types of edits that can be performed on strings: insert a character, remove a character, or replace a character. Given two strings, write a function to check if they are one edi…
原文链接: https://leetcode-cn.com/problems/pattern-matching-lcci 英文原文You are given two strings, pattern and value. The pattern string consists of just the letters a and b, describing a pattern within a string. For example, the string catcatgocatgo matche…
原文链接: https://leetcode-cn.com/problems/re-space-lcci 英文原文Oh, no! You have accidentally removed all spaces, punctuation, and capitalization in a lengthy document. A sentence like "I reset the computer. It still didn't boot!" became "iresetthecomputeri…
原文链接: https://leetcode-cn.com/problems/longest-word-lcci 英文原文Given a list of words, write a program to find the longest word made of other words in the list. If there are more than one answer, return the one that has smallest lexicographic order. If …
原文链接: https://leetcode-cn.com/problems/multi-search-lcci 英文原文Given a string band an array of smaller strings T, design a method to search b for each small string in T. Output positions of all strings in smalls that appear in big, where positions[i] i…
原文链接: https://leetcode-cn.com/problems/calculator-lcci 英文原文Given an arithmetic equation consisting of positive integers, +, -, * and / (no paren­theses), compute the result. The expression string contains only non-negative integers, +, -, *, / op…
原文链接: https://leetcode-cn.com/problems/word-transformer-lcci 英文原文Given two words of equal length that are in a dictionary, write a method to transform one word into another word by changing only one letter at a time. The new word you get in each step…
原文链接: https://leetcode-cn.com/problems/boolean-evaluation-lcci 英文原文Given a boolean expression consisting of the symbols 0 (false), 1 (true), & (AND), | (OR), and ^ (XOR), and a desired boolean result value result, implement a function to count the nu…
原文链接: https://leetcode-cn.com/problems/baby-names-lcci 英文原文Each year, the government releases a list of the 10000 most common baby names and their frequencies (the number of babies with that name). The only problem with this is that some names have m…
原文链接: https://leetcode-cn.com/problems/find-closest-lcci 英文原文You have a large text file containing words. Given any two words, find the shortest distance (in terms of number of words) between them in the file. If the operation will be repeated many t…
原文链接: https://leetcode-cn.com/problems/t9-lcci 英文原文On old cell phones, users typed on a numeric keypad and the phone would provide a list of words that matched these numbers. Each digit mapped to a set of 0 - 4 letters. Implement an algo­rithm to…
原文链接: https://leetcode-cn.com/problems/word-rectangle-lcci 英文原文Given a list of millions of words, design an algorithm to create the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms …
原文链接: https://leetcode-cn.com/problems/langtons-ant-lcci 英文原文An ant is sitting on an infinite grid of white and black squares. It initially faces right. All squares are white initially. At each step, it does the following: (1) At a white square, flip…
原文链接: https://leetcode-cn.com/problems/UlBDOe 英文原文 中文题目小扣出去秋游,途中收集了一些红叶和黄叶,他利用这些叶子初步整理了一份秋叶收藏集 `leaves`, 字符串 `leaves` 仅包含小写字符 `r` 和 `y`, 其中字符 `r` 表示一片红叶,字符 `y` 表示一片黄叶。 出于美观整齐的考虑,小扣想要将收藏集中树叶的排列调整成「红、黄、红」三部分。每部分树叶数量可以不相等,但均需大于等于 1。每次调整操作,小扣可以将一片红叶替换成黄叶…