easy

LeetCode 解答 #53. Maximum Subarray プログラミング練習

問題: 難易度: easy 入力: int[] 目的: 入力されたArrayの中で和が最も大きなSubArrayを求めよ 出力: int求めるのはSubArrayなので、入力の中で連続な数字の和を計算していきます。 値が小さくなると言うことは、前の累計がマイナスだったと言うことなので…

LeetCode 解答 #38. Count and Say プログラミング練習

問題: 難易度: easy 入力: int 目的: 入力された整数をある法則に従って出力せよ 出力: String法則: 例文にあるように、法則は以下の通りです: まず読み方: 1: one one 2: one two 11: two one 111: three one 1121: two one one two one one次に関数の入力…

LeetCode 解答 #35. Search Insert Position プログラミング練習

問題: 難易度: easy 入力: int型array、(int)target 目的: ソートされた入力arrayの中で、targetを差し込む場所を求めよ。 出力: int入力がArray ->ターゲットを探せ的な問題はまずバイナリサーチを思い浮かべましょう。 ♯33、♯34と似た問題です。 入力はソ…

LeetCode 解答 #28. Implement strStr() プログラミング練習

問題: 難易度: easy 入力: 文字列haystackと文字列needle 目的: haystackの中でneedleと一致する文字列が存在する場合一致する最初のインデックスを返せ。存在しない場合は-1を返せ 出力: integer入力された文字列haystackの中にneedleの文字列がsubstring…

LeetCode 解答 #27. Remove Element プログラミング練習

問題: 難易度: easy 入力: integerのリストと整数val 目的: リストの中でvalと同じ値の数値を取り除き新しいリストの長さを返せ 出力: integer前回の♯26と殆ど同じな問題です。 関数では整数を返すようになっていますが、 裏側では下の様なコードを走らせ、…

LeetCode 解答 #26. Remove Duplicates from Sorted Array プログラミング練習

問題: 難易度: medium 入力: integerのリスト 目的: リストの中で重複する数字を取り除き、その長さを返せ 出力: integer入力されたリストが既にソートされているので 重複している数字はすべて隣接の位置にある事になります。 関数では整数を返すようにな…

LeetCode #21. Merge Two Sorted Lists プログラミング練習

問題: 難易度: easy 入力: ListNode 目的: 入力された二つのソートされたLinkedListをマージせよ 出力: ListNoderecursiveでもforでも回答できます。 基礎的な問題なので特に罠もなく一つずつ大きさを比較しながらマージしていきましょう。 注意すべき事: f…

LeetCode #20. Valid Parentheses プログラミング練習

問題: 難易度: easy 入力: String 目的: 入力された括弧が有効かどうかを判断せよ 出力: boolean入力されるのは'(', ')', '{', '}', '[' と ']'の組み合わせです。 入力された括弧群が有効かどうかを判断します。 例えば((())), [()]等でしたら有効で、 [(]…

LeetCode #14. Longest Common Prefix プログラミング練習

問題: 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"…

LeetCode #13. Roman to Integer プログラミング練習

問題: 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…

LeetCode #9. Palindrome Number プログラミング練習

問題: 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…

LeetCode #7. Reverse Integer プログラミング練習

問題: 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…

LeetCode #1 Two Sum プログラミング練習

こんにちは!初はてなブログです。日本人にはあまり馴染みのないかもしれないLeetCodeですが、実はアメリカや中国では情報系の学生なら誰もが一日一問解いていると言われる超有名練習問題です。(実はグーグルやフェイスブック等アメリカ有名企業の面接問題…