java.lang.Object
g1901_2000.s1996_the_number_of_weak_characters_in_the_game.Solution

public class Solution extends Object
1996 - The Number of Weak Characters in the Game.<p>Medium</p> <p>You are playing a game that contains multiple characters, and each of the characters has <strong>two</strong> main properties: <strong>attack</strong> and <strong>defense</strong>. You are given a 2D integer array <code>properties</code> where <code>properties[i] = [attack<sub>i</sub>, defense<sub>i</sub>]</code> represents the properties of the <code>i<sup>th</sup></code> character in the game.</p> <p>A character is said to be <strong>weak</strong> if any other character has <strong>both</strong> attack and defense levels <strong>strictly greater</strong> than this character&rsquo;s attack and defense levels. More formally, a character <code>i</code> is said to be <strong>weak</strong> if there exists another character <code>j</code> where <code>attack<sub>j</sub> > attack<sub>i</sub></code> and <code>defense<sub>j</sub> > defense<sub>i</sub></code>.</p> <p>Return <em>the number of <strong>weak</strong> characters</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> properties = [[5,5],[6,3],[3,6]]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> No character has strictly greater attack and defense than the other.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> properties = [[2,2],[3,3]]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> The first character is weak because the second character has a strictly greater attack and defense.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> properties = [[1,5],[10,4],[4,3]]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> The third character is weak because the second character has a strictly greater attack and defense.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= properties.length <= 10<sup>5</sup></code></li> <li><code>properties[i].length == 2</code></li> <li><code>1 <= attack<sub>i</sub>, defense<sub>i</sub> <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numberOfWeakCharacters

      public int numberOfWeakCharacters(int[][] properties)