DullCodes’s diary

programming,c++,python,MachineLearning,Math,Django,Competitive

leetcode

Leetcode Easy 500. Keyboard Row

Statement https://leetcode.com/problems/keyboard-row/ Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below. 要するにキーボードの列 "QWERTYUIP", "ASD…

Leetcode Easy 1185. Day of the Week

Statement (Good, Bad) = (64, 748) https://leetcode.com/problems/day-of-the-week/ 年月日が整数値で与えられるので曜日を返せ Example Example 1: Input: day = 31, month = 8, year = 2019 Output: "Saturday" Example 2: Input: day = 18, month = 7, …

Leetcode Easy 1078. Occurrences After Bigram

Statement Example Constrains Answer 1 Statement https://leetcode.com/problems/occurrences-after-bigram/ string text, first, secondという文字列が与えられる text は空白に文字列が区切ってある その中にfirst, second が必ず存在している text[i] =…

Leetcode Easy 1030. Matrix Cells in Distance Order

Statement Example Constrains Answer 1 Statement https://leetcode.com/problems/matrix-cells-in-distance-order/ 行R 列C と 特定の点 (r0, c0)が与えられる (r, c), where 0 <= r < R and 0 <= c < C 特定の点から座標にある全ての点のマンハッタン距離…

LeetCode Easy 893. Groups of Special-Equivalent Strings

Statement Example Constrains Answer 1 Statement https://leetcode.com/problems/groups-of-special-equivalent-strings/ any two even indexed ってのは、一つ離れたインデックスのこと [0] - [2], [1] - [3], [2] - [4] みたいなやつら Exampleを見ると…

Leetcode Easy 1370. Increasing Decreasing String

Statement Example Constrains Answer 1 Answer 2 Statement https://leetcode.com/problems/increasing-decreasing-string/ Example Example 1: Input: s = "aaaabbbbcccc" Output: "abccbaabccba" Explanation: After steps 1, 2 and 3 of the first itera…

Leetcode Easy 1025. Divisor Game

Statement Example Constrains Answer 1 Statement Alice and Bob take turns playing a game, with Alice starting first. Initially, there is a number N on the chalkboard. On each player's turn, that player makes a move consisting of: Choosing a…

Leetcode Easy 908. Smallest Range I

Statement Example Constrains Answer 1 Answer 2 Answer 3 Statement (Good, Bad) = (176, 902) Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K, and add x to A[i]. After this process, we have some array…

Leetcode Easy 821. Shortest Distance to a Character

Statement Example Constrains Answer 1 Statement Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string. 文字列 S と 文字 Cが与えられる 文字列 Sの中にある文字Cと…

Leetcode Easy 509. Fibonacci Number

Statement Example Constrains Answer 1 Answer 2 Statement The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That i…

Leetcode Easy 1002. Find Common Characters

Statement Example Constrains Answer 1 Statement Given an array A of strings made only from lowercase letters, return a list of all characters that show up in all strings within the list (including duplicates). For example, if a character o…

Leetcode Easy 1047. Remove All Adjacent Duplicates In String

Statement Example Constrains Answer 1 Answer 2 Statement Given a string S of lowercase letters, a duplicate removal consists of choosing two adjacent and equal letters, and removing them. We repeatedly make duplicate removals on S until we…

Leetcode Easy 1200. Minimum Absolute Difference

Statement Example Constrains Answer 1 Statement Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements. Return a list of pairs in ascending order(with respect to pairs),…

Leetcode Easy 999. Available Captures for Rook

Statement Example Constrains Answer 1 Statement https://leetcode.com/problems/available-captures-for-rook/ 8 x 8 の盤面が与えられる Rがポーンを取れる数を返せ Example Input: [ [".",".",".",".",".",".",".","."], [".",".",".","p",".",".",".",…

Leetcode Easy 344. Reverse String

Statement Example Constrains Answer 1 Answer 2 Statement Write a function that reverses a string. The input string is given as an array of characters char[]. Do not allocate extra space for another array, you must do this by modifying the …

Leetcode Easy 1160. Find Words That Can Be Formed by Characters

Statement Example Constrains Answer 1 Statement You are given an array of strings words and a string chars. A string is good if it can be formed by characters from chars (each character can only be used once). Return the sum of lengths of …

Leetcode Easy 1122. Relative Sort Array

Statement Example Constrains Answer 1 Statement Given two arrays arr1 and arr2, the elements of arr2 are distinct, and all elements in arr2 are also in arr1. Sort the elements of arr1 such that the relative ordering of items in arr1 are th…

Leetcode Easy 929. Unique Email Addresses

Statement Example Constrains Answer 1 Statement https://leetcode.com/problems/unique-email-addresses/ Example Example 1: Input: [ "test.email+alex@leetcode.com", "test.e.mail+bob.cathy@leetcode.com", "testemail+david@lee.tcode.com"] Output…

Statement Example Constrains Answer 1 Statement Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. 文字列が与えられる 空白で区切って、それぞ…

Leetcode Easy 1237. Find Positive Integer Solution for a Given Equation

Statement Example Constrains Answer 1 Statement (Good, Bad) = (73, 298) Given a function f(x, y) and a value z, return all positive integer pairs x and y where f(x,y) == z. The function is constantly increasing, i.e.: f(x, y) < f(x + 1, y)…

Leetcode Easy 811. Subdomain Visit Count

Statement Example Constrains Answer 1 Statement 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.leet…

Leetcode Easy 922 Sort Array By Parity II

Statement Example Constrains Answer 1 Double Ended Queue Answer 2 Statement Given an array A of non-negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] is odd, i is …

Leetcode Easy 1051. Height Checker

Statement Example Constrains Answer 1 Statement Students are asked to stand in non-decreasing order of heights for an annual photo. Return the minimum number of students that must move in order for all students to be standing in non-decrea…

Leetcode Easy 1337. The K Weakest Rows in a Matrix

Statement Example Constrains Answer 1 Statement Given a m * n matrix mat of ones (representing soldiers) and zeros (representing civilians), return the indexes of the k weakest rows in the matrix ordered from the weakest to the strongest. …

Leetcode Easy 1356. Sort Integers by The Number of 1 Bits

Statement Example Constrains Answer 1 Answer 2 Answer 3 Statement Given an integer array arr. You have to sort the integers in the array in ascending order by the number of 1's in their binary representation and in case of two or more inte…

LeetCode Easy 700. Search in a Binary Search Tree

Statement Example Constrains Answer 1 Statement Given the root node of a binary search tree (BST) and a value. You need to find the node in the BST that the node's value equals the given value. Return the subtree rooted with that node. If …

Leetcode Easy 933. Number of Recent Calls

Statement Example Constrains Answer 1 やばい問題 leetcode 933 super bad problem Statement Write a class RecentCounter to count recent requests. It has only one method: ping(int t), where t represents some time in milliseconds. Return the n…

Leetcode Easy 852. Peak Index in a Mountain Array

Statement Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] Given an array that is definitely …

Leetcode Easy 561. Array Partition I

Statement Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible. 2n 個の整数値の配列が与…

Leetcode Easy 942. DI String Match

Statement Given a string S that only contains "I" (increase) or "D" (decrease), let N = S.length. Return any permutation A of [0, 1, ..., N] such that for all i = 0, ..., N-1: - If S[i] == "I", then A[i] < A[i+1] - If S[i] == "D", then A[i…