次のような簡単な問題です:
文字列 word と文字 x のインデックス 0 の配列が与えられます。
文字 x を含む単語を表すインデックスの配列を返します。
返される配列の順序は任意であることに注意してください。
例 1:
入力: 単語 = ["leet","code"]、x = "e"
出力: [0,1]
説明: 「e」は、「leet」と「code」の両方の単語に出現します。したがって、インデックス 0 と 1 を返します。例 2:
入力: 単語 = ["abc","bcd","aaaa","cbc"], x = "a"
出力: [0,2]
説明: 「abc」および「aaaa」には「a」が出現します。したがって、インデックス 0 と 2 を返します。例 3:
入力: 単語 = ["abc","bcd","aaaa","cbc"], x = "z"
出力: []
説明: どの単語にも「z」は出現しません。したがって、空の配列を返します。制約:
1
1
x は英小文字です。
words[i] は英小文字のみで構成されます。
この問題を解決するには、単語リストを反復処理し、各単語で文字が含まれているかどうかを確認し、含まれている場合はそのインデックスを応答リストに保存する必要があります。
class Solution { public List<integer> findWordsContaining(String[] words, char x) { // create response final List<integer> indexes = new ArrayList(); // iterate words string array for(int i=0;i<words.length check if char exists into the word indexes.add yes add index response return searched indexes> <blockquote> <p>実行時間: 1 ミリ秒、Java オンライン送信の 100.00% より高速です。</p> <p>メモリ使用量: 44.95 MB、Java オンライン送信の 49.76% 未満。</p> </blockquote> <p>—</p> <p>ラムダ/関数のアプローチを使用する場合は、通常はクリーンですが、パフォーマンスへの負担が大きくなります。<br> </p> <pre class="brush:php;toolbar:false">class Solution { public List<integer> findWordsContaining(String[] words, char x) { return IntStream.range(0, words.length) .boxed() // convert primitive into Class related (int -> Integer) .map(i -> getIndexIfCharExistsInWord(words[i], i, x)) .filter(Objects::nonNull) // to remove null ones from mapping .collect(Collectors.toList()); } public Integer getIndexIfCharExistsInWord(final String word, final int i, final char x) { return word.indexOf(x) != -1 ? i : null; } } </integer>
実行時間: 9 ミリ秒、Java オンライン送信の 2.72% よりも高速です。
メモリ使用量: 44.90 MB、Java オンライン提出の 66.32% 未満。
—
それだけです!他に議論したいことがあれば、お気軽にコメントしてください。何か見逃した場合はお知らせください。適宜更新します。
次の投稿まで! :)
以上がLeetcode — 文字を含む単語の検索の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

jvm'sperformanceiscompetitivewitherruntimes、sped、safety、andproductivityの提供

javaachievesplatformedentenceTheThejavavirtualMachine(JVM)、avainwithcodetorunonanyplatformwithajvm.1)codescompiledintobytecode、notmachine-specificcode.2)

thejvmisanabstractcomputingMachineCrucialForrunningJavaProgramsDuetoitsPlatForm-IndopentInterChitecture.Itincludes:1)ClassLoaderForloadingClasses、2)Runtimedataareaforforforatastorage、3)executionEngineWithinterter、Jitcompiler、およびGarbagecolfecolfecolfececolfecolfer

jvmhasacloserelationshiptheosasittrantesjavabytecodecodecodecodecodecodecodecodecodecodecodecodecodetructions、manageSmemory、およびhandlesgarbagecollection.thisrelationshipallowsjavatorunonvariousosenvirnments、Butalsedentsはspeedifediferentjvmbeviorhiorsandosendisfredediferentjvmbehbehioorysando

Javaの実装「Write and、Run Everywherewhere」はBytecodeにコンパイルされ、Java仮想マシン(JVM)で実行されます。 1)Javaコードを書き、それをByteCodeにコンパイルします。 2)JVMがインストールされたプラットフォームでByteCodeが実行されます。 3)Javaネイティブインターフェイス(JNI)を使用して、プラットフォーム固有の機能を処理します。 JVMの一貫性やプラットフォーム固有のライブラリの使用などの課題にもかかわらず、Woraは開発効率と展開の柔軟性を大幅に向上させます。

javaachievesplatformentenceTheTheTheJavavirtualMachine(JVM)、CodetorunondifferentoperatingSystemswithOutModification.thejvmcompilesjavacodeplatform-IndopentedbyTecodeを承認することを許可します

javaispowerfulfulduetoitsplatformindepentence、object-orientednature、richstandardlibrary、performancecapability、andstrongsecurityfeatures.1)platformendependenceallowseplicationStorunonaydevicesupportingjava.2)オブジェクト指向のプログラマン型

上位のJava関数には、次のものが含まれます。1)オブジェクト指向プログラミング、サポートポリ型、コードの柔軟性と保守性の向上。 2)例外処理メカニズム、トライキャッチ式ブロックによるコードの堅牢性の向上。 3)ゴミ収集、メモリ管理の簡素化。 4)ジェネリック、タイプの安全性の向上。 5)コードをより簡潔で表現力豊かにするためのAMBDAの表現と機能的なプログラミング。 6)最適化されたデータ構造とアルゴリズムを提供するリッチ標準ライブラリ。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

ドリームウィーバー CS6
ビジュアル Web 開発ツール

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

WebStorm Mac版
便利なJavaScript開発ツール
