- 運営しているクリエイター
2022年8月の記事一覧
ほぼ日刊競プロ ABC182 C - To 3 ちょっと深掘り
C - To 3
問題文
各桁に 0 が出現しないような正の整数 N が与えられます。
N の桁数を k とします。N の桁を 0 個以上 k 個未満消して、残った桁をそのままの順序で結合することで 3 の倍数を作りたいです。
3 の倍数を作ることができるか判定し、作ることができるなら作るのに必要な最少の消す桁数を求めてください。
考えたこと深く考えずにitertoolsを使った組み合わせで解を
ほぼ日刊競プロ leetcode 1323. Maximum 69 Number
1323. Maximum 69 Number
You are given a positive integer num consisting only of digits 6 and 9.
Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6).
考えた
ほぼ日刊競プロ ABC266 A - Middle Letter
A - Middle Letter
問題文
英小文字からなる長さが奇数の文字列 S が与えられます。
S の中央の文字を出力してください。
考えたこと文字列の数は奇数なので、文字列の数//2で割れば中心の文字列のindexが求められる。(//2で割った場合切り捨て)
S= input()print (S[len(S)//2])
ほぼ日刊競プロ leetcode 2. Add Two Numbers
2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two
ほぼ日刊競プロ leetcode 448. Find All Numbers Disappeared in an Array
448. Find All Numbers Disappeared in an Array
Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums
ほぼ日刊競プロ leetcode 392. Is Subsequence
392. Is Subsequence
Given two strings s and t, return true if s is a subsequence of t, or false otherwise.
A subsequence of a string is a new string that is formed from the original string by deleting
ほぼ日刊競プロ leetcode 344. Reverse String
344. Reverse String
Write a function that reverses a string. The input string is given as an array of characters s.
You must do this by modifying the input array in-place with O(1) extra memory.
考えたこ
ほぼ日刊競プロ leetcode 338. Counting Bits
338. Counting Bits
Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation of i.
考えたこと以下の3パターンを考えた.
1.2進数に
ほぼ日刊競プロ leetcode 46. Permutations
46. Permutations
Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.
考えたこと配列が与えられるので,順列を生成し返せばよい.pythonにはitertoolsを使えば組み合わせや順列を生成でき
ほぼ日刊競プロ leetcode 283. Move Zeroes
283. Move Zeroes
Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.
Note that you must do this in-place without making a copy of
ほぼ日刊競プロ leetcode 136. Single Number
136. Single Number
Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.
You must implement a solution with a linear runtime complexity and use on
ほぼ日刊競プロ leetcode 160. Intersection of Two Linked Lists
160. Intersection of Two Linked Lists
Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all,
ほぼ日刊競プロ leetcode 234. Palindrome Linked List
234. Palindrome Linked List
Given the head of a singly linked list, return true if it is a palindrome.
palindromeは回文を意味する.
考えたこと回文判定をしていけば良いので,回帰で連結リストをたぐっていき,中の値をリストに入れていく.最後にそのリストを逆さまにしても同じ結果が出るかを
ほぼ日刊競プロ leetcode 70. Climbing Stairs
70. Climbing Stairs
You are climbing a staircase. It takes n steps to reach the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
考えたこと0段の階段だと1パターン