Skip to content

Latest commit

 

History

History
32 lines (25 loc) · 686 Bytes

Question_2114.md

File metadata and controls

32 lines (25 loc) · 686 Bytes

LeetCode Records - Question 2114 Maximum Number of Words Found in Sentences

Attempt 1: Count the number of spaces

class Solution {
    public int mostWordsFound(String[] sentences) {
        int max = 0;

        for (String sentence : sentences) {
            max = Math.max(max, countWords(sentence));
        }

        return max;
    }

    private int countWords(String sentence) {
        int count = 0;

        for (char ch : sentence.toCharArray()) {
            if (ch == ' ') {
                count++;
            }
        }

        return count + 1;
    }
}
  • Runtime: 1 ms (Beats: 100.00%)
  • Memory: 42.42 MB (Beats: 81.79%)