
hashmap
文章平均质量分 75
flyatcmu
这个作者很懒,什么都没留下…
展开
-
Rank Transform of an Array
Given an array of integersarr, replace each element with its rank.The rank represents how large the element is. The rank has the following rules:Rank is an integer starting from 1. The larger the element, the larger the rank. If two elements are equa.原创 2022-04-25 06:06:53 · 183 阅读 · 0 评论 -
Construct K Palindrome Strings
Given a stringsand an integerk, returntrueif you can use all the characters insto constructkpalindrome strings orfalseotherwise.Example 1:Input: s = "annabelle", k = 2Output: trueExplanation: You can construct two palindromes using all ch...原创 2022-03-25 09:57:56 · 151 阅读 · 0 评论 -
Alert Using Same Key-Card Three or More Times in a One Hour Period
LeetCode company workers use key-cards to unlock office doors. Each time a worker uses their key-card, the security system saves the worker's name and the time when it was used. The system emits analertif any worker uses the key-cardthree or more times...原创 2022-03-06 08:13:25 · 108 阅读 · 0 评论 -
Count Nice Pairs in an Array
You are given an arraynumsthat consists of non-negative integers. Let us definerev(x)as the reverse of the non-negative integerx. For example,rev(123) = 321, andrev(120) = 21. A pair of indices(i, j)isniceif it satisfies all of the following con...原创 2022-02-21 15:09:11 · 420 阅读 · 0 评论 -
Find Original Array From Doubled Array
An integer arrayoriginalis transformed into adoubledarraychangedby appendingtwice the valueof every element inoriginal, and then randomlyshufflingthe resulting array.Given an arraychanged, returnoriginalifchangedis adoubledarray. Ifcha...原创 2022-02-11 12:45:29 · 645 阅读 · 0 评论 -
Verifying an Alien Dictionary
In an alien language, surprisingly, they also use English lowercase letters, but possibly in a differentorder. Theorderof the alphabet is some permutation of lowercase letters.Given a sequence ofwordswritten in the alien language, and theorderof t...原创 2022-01-22 05:30:24 · 233 阅读 · 0 评论 -
Number of Ways Where Square of Number Is Equal to Product of Two Numbers
Given two arrays of integersnums1andnums2, return the number of triplets formed (type 1 and type 2) under the following rules:Type 1: Triplet (i, j, k)ifnums1[i]2== nums2[j] * nums2[k]where0 <= i < nums1.lengthand0 <= j < k < num...原创 2020-09-06 13:06:03 · 228 阅读 · 0 评论 -
Analyze User Website Visit Pattern
We are given some website visits: the user with nameusername[i]visited the websitewebsite[i]at timetimestamp[i].A3-sequenceis a list ofwebsites of length 3 sorted in ascending orderby the time of their visits. (The websites in a 3-sequence are ...原创 2020-08-26 12:06:08 · 664 阅读 · 0 评论 -
Vertical Order Traversal of a Binary Tree
Given a binary tree, return thevertical ordertraversal of its nodesvalues.For each node at position(X, Y), its left and right children respectivelywill be at positions(X-1, Y-1)and(X+1, Y-1).Running a vertical line fromX = -infinitytoX = +in...原创 2020-08-10 13:02:13 · 228 阅读 · 0 评论 -
Palindrome Pairs
Given a list ofuniquewords, find all pairs ofdistinctindices(i, j)in the given list, so that the concatenation of the two words, i.e.words[i] + words[j]is a palindrome.Example 1:Input: ["abcd","dcba","lls","s","sssll"]Output: [[0,1],[1,0],[3,...原创 2020-06-21 12:46:15 · 284 阅读 · 0 评论 -
Brick Wall
There is a brick wall in front of you. The wall is rectangular and has several rows of bricks. The bricks have the same height but different width. You want to draw a vertical line from thetopto thebottomand cross theleastbricks.The brick wall is r...原创 2020-06-20 04:49:22 · 328 阅读 · 0 评论 -
Rank Teams by Votes
In a special ranking system,each voter gives a rank from highest to lowest to all teams participated in the competition.The ordering of teams is decided by who received the most position-one votes. If two or more teams tie in the first position, we cons.原创 2020-06-18 12:18:30 · 451 阅读 · 0 评论 -
Image Overlap
Two imagesAandBare given, represented asbinary, square matrices of the same size. (A binary matrix has only 0s and 1s as values.)We translate one image however we choose (sliding it left, right, up, or down any number of units), and place it on top...原创 2020-06-16 13:29:49 · 284 阅读 · 0 评论 -
Find Two Non-overlapping Sub-arrays Each With Target Sum
Given an array of integersarrand an integertarget.You have to findtwo non-overlapping sub-arraysofarreach with sum equaltarget. There can be multiple answers so you have to find an answer where the sum of the lengths of the two sub-arrays ismini...原创 2020-06-16 12:24:37 · 319 阅读 · 0 评论 -
Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.Given a list of stones' positions (in units) in sorted ascending order, d原创 2020-06-13 12:56:18 · 590 阅读 · 0 评论 -
Contiguous Array
Given a binary array, find the maximum length of a contiguous subarray with equal number of 0 and 1.Example 1:Input: [0,1]Output: 2Explanation: [0, 1] is the longest contiguous subarray with equal number of 0 and 1.Example 2:Input: [0,1,0]Out原创 2020-06-13 07:10:01 · 259 阅读 · 0 评论 -
Diagonal Traverse II
Given a list of lists of integers,nums,return all elements ofnumsin diagonal order as shown in the below images.Example 1:Input: nums = [[1,2,3],[4,5,6],[7,8,9]]Output: [1,4,2,7,5,3,8,6,9]Example 2:Input: nums = [[1,2,3,4,5],[6,7],[8...原创 2020-06-12 13:13:54 · 203 阅读 · 0 评论 -
Find Duplicate File in System
Given a list of directory info including directory path, and all the files with contents in this directory, you need to find out all the groups of duplicate files in the file system in terms of their paths.A group of duplicate files consists of at least.原创 2020-06-10 06:49:49 · 300 阅读 · 0 评论 -
Fraction to Recurring Decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the repeating part in parentheses.For原创 2014-12-18 05:51:16 · 847 阅读 · 0 评论 -
[LeetCode] Continuous Subarray Sum
Given a list ofnon-negativenumbers and a targetintegerk, write a function to check if the array has a continuous subarray of size at least 2 that sums up to a multiple ofk, that is, sums up to n*k where n is also aninteger.Example 1:Input: [23, ...原创 2020-05-26 04:41:54 · 260 阅读 · 0 评论 -
String Transforms Into Another String
Given two stringsstr1andstr2of the same length, determine whether you can transformstr1intostr2by doingzero or moreconversions.In one conversion you can convertalloccurrences of one character instr1toanyother lowercase English character....原创 2020-05-25 10:07:16 · 250 阅读 · 0 评论 -
Group Shifted Strings
Given a string, we can "shift" each of its letter to its successive letter, for example:"abc" -> "bcd". We can keep "shifting" which forms the sequence:"abc" -> "bcd" -> ... -> "xyz"Given a list of strings which contains only lowercase al.原创 2020-05-17 10:28:24 · 152 阅读 · 0 评论 -
Contains Duplicate
Given an array of integers, find if the array contains any duplicates.Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.Example 1:Input: [1,2,3,1]Output: true原创 2020-05-13 11:53:16 · 165 阅读 · 0 评论 -
Contains Duplicate II
Given an array of integers and an integerk, find out whether there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and theabsolutedifference betweeniandjis at mostk.Example 1:Input: nums = [1,2,3,1], k = 3Output: tru...原创 2020-05-13 10:27:55 · 135 阅读 · 0 评论 -
Binary Tree Vertical Order Traversal
Given a binary tree, return thevertical ordertraversal of its nodes' values. (ie, from top to bottom, column by column).If two nodes are in the same row and column, the order should be fromleft t...原创 2020-02-14 12:26:38 · 235 阅读 · 0 评论 -
Design HashSet
Design a HashSetwithout using any built-in hash table libraries.To be specific, your design should include these functions:add(value):Insert a value into the HashSet. contains(value): Return whether the value exists in the HashSet or not. remove(...原创 2020-05-10 07:23:06 · 187 阅读 · 0 评论 -
My Calendar I
Implement aMyCalendarclass to store your events. A new event can be added if adding the event will not cause a double booking.Your class will have the method,book(int start, int end). Formally, t...原创 2020-05-04 01:54:17 · 352 阅读 · 0 评论 -
Subdomain Visit Count
A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the lowest level, "discuss.leetcode.com"...原创 2020-05-01 12:59:47 · 195 阅读 · 0 评论 -
Two Sum III - Data structure design
Design and implement a TwoSum class. It should support the following operations:addandfind.add- Add the number to an internal data structure.find- Find if there exists any pair of numbers whi原创 2014-12-26 09:47:58 · 1983 阅读 · 0 评论 -
Two Sum
Given an array of integers, find two numbers such that they add up to a specific target number.The functiontwoSumshould returnindicesof the two numbers such that they add up to the target, where...原创 2016-08-17 10:35:43 · 215 阅读 · 0 评论 -
Confusing Number
Given a numberN, returntrueif and only if it is aconfusing number, which satisfies the following condition:We can rotate digits by 180 degrees to form new digits. When 0, 1, 6, 8, 9 are rotated ...原创 2020-03-27 14:11:33 · 169 阅读 · 0 评论 -
Design HashMap
Design a HashMapwithout using any built-in hash table libraries.To be specific, your design should include these functions:put(key, value):Insert a (key, value) pair into the HashMap. If the va...原创 2020-03-15 01:50:48 · 247 阅读 · 0 评论 -
Most Common Word
Given a paragraphand a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at least one word that isn't banned, and that the answer...原创 2020-03-14 14:11:19 · 131 阅读 · 0 评论 -
Bulls and Cows
You are playing the followingBulls and Cowsgame with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint tha...原创 2020-03-12 15:10:09 · 364 阅读 · 0 评论 -
Sentence Similarity
Given two sentenceswords1, words2(each represented as an array of strings), and a list of similar word pairspairs, determine if two sentences are similar.For example, "great acting skills" and "f...原创 2020-03-10 12:12:10 · 248 阅读 · 0 评论 -
Typeahead
Implement typeahead. Given a string and a dictionary, return all words that contains the string as a substring. The dictionary will give at the initialize method and wont be changed. The method to fin...原创 2020-02-17 11:04:55 · 166 阅读 · 0 评论 -
Rotate Digits
X is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from X. Each digit must be rotated - we cannot choose to leave it alone.A number...原创 2020-02-13 12:23:13 · 228 阅读 · 0 评论 -
Find the Town Judge
In a town, there areNpeople labelled from1toN. There is a rumor that one of these people is secretly the town judge.If thetown judge exists, then:The town judge trusts nobody. Everybody (e...原创 2020-02-11 15:30:34 · 150 阅读 · 0 评论 -
Minimum Domino Rotations For Equal Row
In a row of dominoes,A[i]andB[i]represent the top and bottom halves of thei-th domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.)We may rotate thei-th d...原创 2020-02-10 13:44:36 · 264 阅读 · 0 评论 -
Inverted Index
Create an inverted index with given documents.ExampleGiven a list of documents with id and content. (class Document)Return an inverted index (HashMap with key is the word and value is a list of d...原创 2020-02-10 05:57:04 · 205 阅读 · 0 评论