java
問題: 難易度: medium 入力: integerのリスト 目的: リストの中で重複する数字を取り除き、その長さを返せ 出力: integer入力されたリストが既にソートされているので 重複している数字はすべて隣接の位置にある事になります。 関数では整数を返すようにな…
問題: 難易度: hard 入力: ListNode 目的: 隣接のn個のノードをすべてスワップして返せ 出力: ListNode前回の♯23問の延長問題です。 23問目は隣接二つのノードをスワップする問題でしたが、 今回の問題は隣接n個のノードをスワップしなければなりません。 …
問題: 難易度: medium 入力: ListNode 目的: 隣接の二つのノードをすべてスワップして返せ 出力: ListNodeLinkedListの問題が立て込んでますね。 やはりArrayとは違い、LinkedLIstはノード毎に繋がりをもっているので、 ただ隣接のノードの値を交換するので…
問題: 難易度: hard 入力: ListNodeのリスト 目的: 入力されたLinkedLIstをマージせよ 出力: ListNode♯21問めに、二つのソートされたLinkedListをマージする問題がありましたが、 今回はそれの延長問題です。 21問目と同様、入力のリスト群はすべてソートさ…
問題: 難易度: medium 入力: 正数n 目的: n個の括弧で有効組み合わせをすべて求めよ 出力: Stringのリスト前回の♯21で括弧群の有効かどうかを判断しました。 今回は有効な組み合わせをすべて求める問題です。 21問目と違い括弧は”()”のみなので求めやすく…
問題: 難易度: easy 入力: ListNode 目的: 入力された二つのソートされたLinkedListをマージせよ 出力: ListNoderecursiveでもforでも回答できます。 基礎的な問題なので特に罠もなく一つずつ大きさを比較しながらマージしていきましょう。 注意すべき事: f…
問題: 難易度: easy 入力: String 目的: 入力された括弧が有効かどうかを判断せよ 出力: boolean入力されるのは'(', ')', '{', '}', '[' と ']'の組み合わせです。 入力された括弧群が有効かどうかを判断します。 例えば((())), [()]等でしたら有効で、 [(]…
問題: 難易度: medium 入力: ListNode, n 目的: 入力リストの後ろからn番目のノードを取り除け 出力: ListNodeLinkedListの問題です。 非情報系出身者にはあまり見ないデータ型かもしれませんが、 コーディング面接にはよく出るタイプなので必ず知っておき…
問題: 難易度: medium 入力: int型Array 目的: 入力された整数の内、和がtargetになる四つの整数の組み合わせをすべて出力せよ 出力: int型リストのリスト#15の3Sumの延長問題です。 基本思想は全く同じで、♯15を解けた人なら同じ方法で解けると思います。 …
問題: 難易度: medium 入力: String 目的: 入力されたケータイのボタンを押した時可能な出力をすべて探せ 出力: Stringのリストガラケー時代を思い出しましょう。画像にあるように1は何も表しません。2はabc, 3はdef, 4-ghi, 5-jkl, 6-mno, 7-pqrs, 8-tuv, …
問題: Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.Exampl…
問題: Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note:The solution set must not contain duplicate triplets.Example:Given…
問題: Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".Example 1:Input: ["flower","flow","flight"] Output: "fl" Example 2:Input: ["dog","racecar"…
問題: Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, two is written as II in Roman numeral, just two one's added together. Twelve is written…
最近やっと時間が出来、android studioをかじり始めています。 ItemListを使い、itemをクリックするとそのアイテムに対応した画像を新しいアクティビティで出す と言う簡単なアプリを書いていたのですがどうも出てくる画像がフィットしない。 XMLファイルの…
問題: Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, two is written as II in Roman numeral, just two one's added together. Twelve is written…
問題: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axi…
問題: Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and '*'.'.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entir…
問題: Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 121 Output: true Example 2:Input: -121 Output: false Explanation: From left to right, it reads -121…
問題: Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional ini…
問題: Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123 Output: 321 Example 2:Input: -123 Output: -321 Example 3:Input: 120 Output: 21 Note: Assume we are dealing with an environment which could only store i…
問題: Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad" Output: "bab" Note: "aba" is also a valid answer. Example 2:Input: "cbbd" Output: "bb" 難易…
問題: There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1: nums1 = [1, 3] nums2 = [2]The median is 2.0 Example…
問題: Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the length of 1.Given "pwwkew", the a…
問題: 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 contain a single digit. Add the two numbers and return it as a linked list.You may assum…
こんにちは!初はてなブログです。日本人にはあまり馴染みのないかもしれないLeetCodeですが、実はアメリカや中国では情報系の学生なら誰もが一日一問解いていると言われる超有名練習問題です。(実はグーグルやフェイスブック等アメリカ有名企業の面接問題…