原文链接: https://leetcode-cn.com/problems/is-unique-lcci 英文原文Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures? Example 1: Input: s = "leetcode" Output: false Example 2: Input: s…
标签详情
哈希表 分类
原文链接: https://leetcode-cn.com/problems/check-permutation-lcci 英文原文Given two strings,write a method to decide if one is a permutation of the other. Example 1: Input: s1 = "abc", s2 = "bca" Output: true Example 2: Input: s1 = "abc", s2 = "bad" Output: …
原文链接: https://leetcode-cn.com/problems/remove-duplicate-node-lcci 英文原文Write code to remove duplicates from an unsorted linked list. Example1: Input: [1, 2, 3, 3, 2, 1] Output: [1, 2, 3] Example2: Input: [1, 1, 1, 1, 2] Output: [1, 2] Note: The length…
原文链接: https://leetcode-cn.com/problems/intersection-of-two-linked-lists-lcci 英文原文Given two (singly) linked lists, determine if the two lists intersect. Return the inter­ secting node. Note that the intersection is defined based on reference, not …
原文链接: https://leetcode-cn.com/problems/linked-list-cycle-lcci 英文原文Given a circular linked list, implement an algorithm that returns the node at the beginning of the loop. Circular linked list: A (corrupt) linked list in which a node's next pointer po…
原文链接: https://leetcode-cn.com/problems/palindrome-permutation-lcci 英文原文Given a string, write a function to check if it is a permutation of a palindrome. A palindrome is a word or phrase that is the same forwards and backwards. A permutation is a rear…
原文链接: https://leetcode-cn.com/problems/zero-matrix-lcci 英文原文Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are set to 0. Example 1: Input: [ [1,1,1], [1,0,1], [1,1,1] ] Output: [ [1,0,1], [0,0,0], [1,0,1] …
原文链接: 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/shu-zu-zhong-zhong-fu-de-shu-zi-lcof 中文题目找出数组中重复的数字。 在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。 示例 1: 输入: [2, 3, 1, 0, 2, 5, 3] 输出:2 或 3 限制: 2 <= n <= 100000 通过…
原文链接: https://leetcode-cn.com/problems/zhong-jian-er-cha-shu-lcof 中文题目输入某二叉树的前序遍历和中序遍历的结果,请构建该二叉树并返回其根节点。 假设输入的前序遍历和中序遍历的结果中都不含重复的数字。 示例 1: Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7] Output: [3,9,20,null,null,15,7] 示例 2: Input: preorder…
原文链接: https://leetcode-cn.com/problems/fu-za-lian-biao-de-fu-zhi-lcof 中文题目请实现 copyRandomList 函数,复制一个复杂链表。在复杂链表中,每个节点除了有一个 next 指针指向下一个节点,还有一个 random 指针指向链表中的任意节点或者 null。 示例 1: 输入:head = [[7,null],[13,0],[11,4],[10,2],[1,0]] 输出:[[7,null],[13,0],[11,4]…
原文链接: https://leetcode-cn.com/problems/shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof 中文题目数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字。 你可以假设数组是非空的,并且给定的数组总是存在多数元素。 示例 1: 输入: [1, 2, 3, 2, 2, 2, 5, 4, 2] 输出: 2 限制: 1 <= 数组长度 <= 50000 注意:本题与主站 169 题相同:ht…
原文链接: 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/liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof 中文题目输入两个链表,找出它们的第一个公共节点。 如下面的两个链表: 在节点 c1 开始相交。 示例 1: 输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3 输出:Reference of …
原文链接: https://leetcode-cn.com/problems/que-shi-de-shu-zi-lcof 中文题目一个长度为n-1的递增排序数组中的所有数字都是唯一的,并且每个数字都在范围0~n-1之内。在范围0~n-1内的n个数字中有且只有一个数字不在该数组中,请找出这个数字。 示例 1: 输入: [0,1,3] 输出: 2 示例 2: 输入: [0,1,2,3,4,5,6,7,9] 输出: 8 限制: 1 <= 数组长度 <= 10000 通过代码 高赞题解解题思路: 排序…
原文链接: 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/chou-shu-lcof 中文题目我们把只包含质因子 2、3 和 5 的数称作丑数(Ugly Number)。求按从小到大的顺序的第 n 个丑数。 示例: 输入: n = 10 输出: 12 解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 是前 10 个丑数。 说明: 1 是丑数。 n 不超过1690。 注意:本题与主站 264 题相同:https://leetcode-cn.com/probl…
原文链接: https://leetcode-cn.com/problems/best-line-lcci 英文原文Given a two-dimensional graph with points on it, find a line which passes the most number of points. Assume all the points that passed by the line are stored in list S sorted by their number. …
原文链接: 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/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/lru-cache-lcci 英文原文Design and build a "least recently used" cache, which evicts the least recently used item. The cache should map from keys to values (allowing you to insert and retrieve a value associ­ated…
原文链接: 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/missing-number-lcci 英文原文An array contains all the integers from 0 to n, except for one number which is missing. Write code to find the missing integer. Can you do it in O(n) time? Note: This problem is slightly …
原文链接: https://leetcode-cn.com/problems/find-longest-subarray-lcci 英文原文Given an array filled with letters and numbers, find the longest subarray with an equal number of letters and numbers. Return the subarray. If there are more than one answer, retur…
原文链接: 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/get-kth-magic-number-lcci 英文原文Design an algorithm to find the kth number such that the only prime factors are 3, 5, and 7. Note that 3, 5, and 7 do not have to be factors, but it should not have any other prime …
原文链接: https://leetcode-cn.com/problems/pairs-with-sum-lcci 英文原文Design an algorithm to find all pairs of integers within an array which sum to a specified value. Example 1: Input: nums = [5,6,5], target = 11 Output: [[5,6]] Example 2: Input: nums = [5…
原文链接: https://leetcode-cn.com/problems/shortest-supersequence-lcci 英文原文You are given two arrays, one shorter (with all distinct elements) and one longer. Find the shortest subarray in the longer array that contains all the elements in the shorter arr…