From 4ee6d7ee9b60fb30d6de20d8231aa4c423d7c00c Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Fri, 29 Sep 2023 03:01:55 +0000 Subject: [PATCH 1/2] feat: add solutions to lc problem: No.2868 No.2868.The Wording Game --- .../2800-2899/2868.The Wording Game/README.md | 263 ++++++++++++++++++ .../2868.The Wording Game/README_EN.md | 242 ++++++++++++++++ .../2868.The Wording Game/Solution.cpp | 28 ++ .../2868.The Wording Game/Solution.go | 25 ++ .../2868.The Wording Game/Solution.java | 28 ++ .../2868.The Wording Game/Solution.py | 19 ++ .../2868.The Wording Game/Solution.ts | 25 ++ solution/README.md | 1 + solution/README_EN.md | 1 + solution/summary.md | 1 + solution/summary_en.md | 1 + 11 files changed, 634 insertions(+) create mode 100644 solution/2800-2899/2868.The Wording Game/README.md create mode 100644 solution/2800-2899/2868.The Wording Game/README_EN.md create mode 100644 solution/2800-2899/2868.The Wording Game/Solution.cpp create mode 100644 solution/2800-2899/2868.The Wording Game/Solution.go create mode 100644 solution/2800-2899/2868.The Wording Game/Solution.java create mode 100644 solution/2800-2899/2868.The Wording Game/Solution.py create mode 100644 solution/2800-2899/2868.The Wording Game/Solution.ts diff --git a/solution/2800-2899/2868.The Wording Game/README.md b/solution/2800-2899/2868.The Wording Game/README.md new file mode 100644 index 0000000000000..17e04c881932f --- /dev/null +++ b/solution/2800-2899/2868.The Wording Game/README.md @@ -0,0 +1,263 @@ +# [2868. 单词游戏](https://leetcode.cn/problems/the-wording-game) + +[English Version](/solution/2800-2899/2868.The%20Wording%20Game/README_EN.md) + +## 题目描述 + + + +

Alice 和 Bob 分别拥有一个 按字典序排序 的字符串数组,分别命名为 a 和 b

+ +

他们正在玩一个单词游戏,遵循以下规则:

+ + + +

Alice 通过选择在 字典序最小 的单词开始游戏。

+ +

给定 ab,已知两名玩家都按最佳策略玩游戏,如果 Alice 可以获胜,则返回 true ,否则返回 false

+ +

如果满足以下条件,则称一个单词 w 比另一个单词 z 严格大

+ + + +

如果在 st 不同的第一个位置处,字符串 s 的字母比字符串 t 的字母在字母表中的顺序更靠后,则称为字符串 s字典序上大于 字符串 t。如果前 min(s.length, t.length) 个字符没有区别,那么较长的字符串是在字典序上较大的那一个。

+ +

 

+ +

示例 1:

+ +
+输入: a = ["avokado","dabar"], b = ["brazil"]
+
+输出: false
+
+解释: Alice 必须从单词 "avokado" 来开始游戏,因为这是她最小的单词,然后 Bob 使用他唯一的单词 "brazil",他可以使用它因为它的第一个字母 'b' 在 Alice 的单词的第一个字母 'a' 之后。
+
+Alice 无法出牌,因为剩下的唯一单词的第一个字母既不等于 'b' 也不是 'b' 之后的字母 'c'。
+
+所以,Alice 输了,游戏结束。
+ +示例 2: + +
+输入: a = ["ananas","atlas","banana"], b = ["albatros","cikla","nogomet"]
+
+输出: true
+
+解释: Alice 必须从单词 "ananas" 来开始游戏。
+
+Bob 无法出牌,因为他唯一拥有的以字母 'a' 或 'b' 开头的单词是 "albatros",而它比 Alice 的单词小。
+
+所以,Alice 获胜,游戏结束。
+ +示例 3: + +
+输入: a = ["hrvatska","zastava"], b = ["bijeli","galeb"]
+
+输出: true
+
+解释: Alice 必须从单词 "hrvatska" 来开始游戏。
+
+Bob 无法出牌,因为他的两个单词的第一个字母都比 Alice 的单词的第一个字母 'h' 小。
+
+所以,Alice 获胜,游戏结束。
+ +

 

+ +

约束条件:

+ + + +## 解法 + + + +**方法一:模拟** + +我们记当前轮到 $Alice$ 的回合为 $k=0$,轮到 $Bob$ 的回合为 $k=1$。我们用 $i$ 记录 $Alice$ 的下标,用 $j$ 记录 $Bob$ 的下标,用 $w$ 记录当前轮到的玩家的单词。初始时 $i=1$, $j=0$, $w=a[0]$。 + +我们不断地进行如下操作: + +如果 $k=1$,则我们判断 $j$ 是否等于 $b$ 的长度,如果等于则说明 $Alice$ 获胜,返回 $true$;否则我们判断 $b[j]$ 的第一个字母是否等于 $w$ 的第一个字母,如果等于则我们判断 $b[j]$ 是否大于 $w$,或者 $b[j]$ 的第一个字母是否比 $w$ 的第一个字母大 $1$,如果是则说明 $Bob$ 可以出第 $j$ 个单词,我们令 $w=b[j]$,并将 $k$ 取反;否则说明 $Bob$ 无法出第 $j$ 个单词,我们令 $j$ 加一。 + +如果 $k=0$,则我们判断 $i$ 是否等于 $a$ 的长度,如果等于则说明 $Bob$ 获胜,返回 $false$;否则我们判断 $a[i]$ 的第一个字母是否等于 $w$ 的第一个字母,如果等于则我们判断 $a[i]$ 是否大于 $w$,或者 $a[i]$ 的第一个字母是否比 $w$ 的第一个字母大 $1$,如果是则说明 $Alice$ 可以出第 $i$ 个单词,我们令 $w=a[i]$,并将 $k$ 取反;否则说明 $Alice$ 无法出第 $i$ 个单词,我们令 $i$ 加一。 + +时间复杂度 $O(m + n)$,其中 $m$ 和 $n$ 分别是数组 $a$ 和 $b$ 的长度。我们只需要遍历数组一次。空间复杂度 $O(1)$。 + + + +### **Python3** + + + +```python +class Solution: + def canAliceWin(self, a: List[str], b: List[str]) -> bool: + i, j, k = 1, 0, 1 + w = a[0] + while 1: + if k: + if j == len(b): + return True + if (b[j][0] == w[0] and b[j] > w) or ord(b[j][0]) - ord(w[0]) == 1: + w = b[j] + k ^= 1 + j += 1 + else: + if i == len(a): + return False + if (a[i][0] == w[0] and a[i] > w) or ord(a[i][0]) - ord(w[0]) == 1: + w = a[i] + k ^= 1 + i += 1 +``` + +### **Java** + + + +```java +class Solution { + public boolean canAliceWin(String[] a, String[] b) { + int i = 1, j = 0; + boolean k = true; + String w = a[0]; + while (true) { + if (k) { + if (j == b.length) { + return true; + } + if ((b[j].charAt(0) == w.charAt(0) && w.compareTo(b[j]) < 0) || b[j].charAt(0) - w.charAt(0) == 1) { + w = b[j]; + k = !k; + } + ++j; + } else { + if (i == a.length) { + return false; + } + if ((a[i].charAt(0) == w.charAt(0) && w.compareTo(a[i]) < 0) || a[i].charAt(0) - w.charAt(0) == 1) { + w = a[i]; + k = !k; + } + ++i; + } + } + } +} +``` + +### **C++** + +```cpp +class Solution { +public: + bool canAliceWin(vector& a, vector& b) { + int i = 1, j = 0, k = 1; + string w = a[0]; + while (1) { + if (k) { + if (j == b.size()) { + return true; + } + if ((b[j][0] == w[0] && w < b[j]) || b[j][0] - w[0] == 1) { + w = b[j]; + k ^= 1; + } + ++j; + } else { + if (i == a.size()) { + return false; + } + if ((a[i][0] == w[0] && w < a[i]) || a[i][0] - w[0] == 1) { + w = a[i]; + k ^= 1; + } + ++i; + } + } + } +}; +``` + +### **Go** + +```go +func canAliceWin(a []string, b []string) bool { + i, j, k := 1, 0, 1 + w := a[0] + for { + if k&1 == 1 { + if j == len(b) { + return true + } + if (b[j][0] == w[0] && w < b[j]) || b[j][0]-w[0] == 1 { + w = b[j] + k ^= 1 + } + j++ + } else { + if i == len(a) { + return false + } + if (a[i][0] == w[0] && w < a[i]) || a[i][0]-w[0] == 1 { + w = a[i] + k ^= 1 + } + i++ + } + } +} +``` + +### **TypeScript** + +```ts +function canAliceWin(a: string[], b: string[]): boolean { + let [i, j, k] = [1, 0, 1]; + let w = a[0]; + while (1) { + if (k) { + if (j === b.length) { + return true; + } + if ((b[j][0] === w[0] && w < b[j]) || b[j].charCodeAt(0) - w.charCodeAt(0) === 1) { + w = b[j]; + k ^= 1; + } + ++j; + } else { + if (i === a.length) { + return false; + } + if ((a[i][0] === w[0] && w < a[i]) || a[i].charCodeAt(0) - w.charCodeAt(0) === 1) { + w = a[i]; + k ^= 1; + } + ++i; + } + } +} +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2868.The Wording Game/README_EN.md b/solution/2800-2899/2868.The Wording Game/README_EN.md new file mode 100644 index 0000000000000..00cf72015878e --- /dev/null +++ b/solution/2800-2899/2868.The Wording Game/README_EN.md @@ -0,0 +1,242 @@ +# [2868. The Wording Game](https://leetcode.com/problems/the-wording-game) + +[中文文档](/solution/2800-2899/2868.The%20Wording%20Game/README.md) + +## Description + +

Alice and Bob each have a lexicographically sorted array of strings named a and b respectively.

+ +

They are playing a wording game with the following rules:

+ +
    +
  • On each turn, the current player should play a word from their list such that the new word is closely greater than the last played word; then it's the other player's turn.
  • +
  • If a player can't play a word on their turn, they lose.
  • +
+ +

Alice starts the game by playing her lexicographically smallest word.

+ +

Given a and b, return true if Alice can win knowing that both players play their best, and false otherwise.

+ +

A word w is closely greater than a word z if the following conditions are met:

+ +
    +
  • w is lexicographically greater than z.
  • +
  • If w1 is the first letter of w and z1 is the first letter of z, w1 should either be equal to z1 or be the letter after z1 in the alphabet.
  • +
  • For example, the word "care" is closely greater than "book" and "car", but is not closely greater than "ant" or "cook".
  • +
+ +

A string s is lexicographically greater than a string t if in the first position where s and t differ, string s has a letter that appears later in the alphabet than the corresponding letter in t. If the first min(s.length, t.length) characters do not differ, then the longer string is the lexicographically greater one.

+ +

 

+

Example 1:

+ +
+Input: a = ["avokado","dabar"], b = ["brazil"]
+Output: false
+Explanation: Alice must start the game by playing the word "avokado" since it's her smallest word, then Bob plays his only word, "brazil", which he can play because its first letter, 'b', is the letter after Alice's word's first letter, 'a'.
+Alice can't play a word since the first letter of the only word left is not equal to 'b' or the letter after 'b', 'c'.
+So, Alice loses, and the game ends.
+ +

Example 2:

+ +
+Input: a = ["ananas","atlas","banana"], b = ["albatros","cikla","nogomet"]
+Output: true
+Explanation: Alice must start the game by playing the word "ananas".
+Bob can't play a word since the only word he has that starts with the letter 'a' or 'b' is "albatros", which is smaller than Alice's word.
+So Alice wins, and the game ends.
+ +

Example 3:

+ +
+Input: a = ["hrvatska","zastava"], b = ["bijeli","galeb"]
+Output: true
+Explanation: Alice must start the game by playing the word "hrvatska".
+Bob can't play a word since the first letter of both of his words are smaller than the first letter of Alice's word, 'h'.
+So Alice wins, and the game ends.
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= a.length, b.length <= 105
  • +
  • a[i] and b[i] consist only of lowercase English letters.
  • +
  • a and b are lexicographically sorted.
  • +
  • All the words in a and b combined are distinct.
  • +
  • The sum of the lengths of all the words in a and b combined does not exceed 106.
  • +
+ +## Solutions + +**Solution 1: Simulation** + +We use $k$ to record whose turn it is, where $k=0$ means it is Alice's turn, and $k=1$ means it is Bob's turn. We use $i$ to record Alice's index, $j$ to record Bob's index, and $w$ to record the current word. Initially, we set $i=1$, $j=0$, and $w=a[0]$. + +We perform the following steps repeatedly: + +If $k=1$, we check if $j$ is equal to the length of $b$. If it is, then Alice wins and we return $true$. Otherwise, we check if the first letter of $b[j]$ is equal to the first letter of $w$. If it is, we check if $b[j]$ is greater than $w$, or if the first letter of $b[j]$ is one greater than the first letter of $w$. If either of these conditions is true, then Bob can play the $j$-th word. We set $w=b[j]$ and toggle $k$. Otherwise, Bob cannot play the $j$-th word, so we increment $j$. + +If $k=0$, we check if $i$ is equal to the length of $a$. If it is, then Bob wins and we return $false$. Otherwise, we check if the first letter of $a[i]$ is equal to the first letter of $w$. If it is, we check if $a[i]$ is greater than $w$, or if the first letter of $a[i]$ is one greater than the first letter of $w$. If either of these conditions is true, then Alice can play the $i$-th word. We set $w=a[i]$ and toggle $k$. Otherwise, Alice cannot play the $i$-th word, so we increment $i$. + +The time complexity is $O(m+n)$, where $m$ and $n$ are the lengths of arrays $a$ and $b$, respectively. We only need to traverse the arrays once. The space complexity is $O(1)$. + + + +### **Python3** + +```python +class Solution: + def canAliceWin(self, a: List[str], b: List[str]) -> bool: + i, j, k = 1, 0, 1 + w = a[0] + while 1: + if k: + if j == len(b): + return True + if (b[j][0] == w[0] and b[j] > w) or ord(b[j][0]) - ord(w[0]) == 1: + w = b[j] + k ^= 1 + j += 1 + else: + if i == len(a): + return False + if (a[i][0] == w[0] and a[i] > w) or ord(a[i][0]) - ord(w[0]) == 1: + w = a[i] + k ^= 1 + i += 1 +``` + +### **Java** + +```java +class Solution { + public boolean canAliceWin(String[] a, String[] b) { + int i = 1, j = 0; + boolean k = true; + String w = a[0]; + while (true) { + if (k) { + if (j == b.length) { + return true; + } + if ((b[j].charAt(0) == w.charAt(0) && w.compareTo(b[j]) < 0) || b[j].charAt(0) - w.charAt(0) == 1) { + w = b[j]; + k = !k; + } + ++j; + } else { + if (i == a.length) { + return false; + } + if ((a[i].charAt(0) == w.charAt(0) && w.compareTo(a[i]) < 0) || a[i].charAt(0) - w.charAt(0) == 1) { + w = a[i]; + k = !k; + } + ++i; + } + } + } +} +``` + +### **C++** + +```cpp +class Solution { +public: + bool canAliceWin(vector& a, vector& b) { + int i = 1, j = 0, k = 1; + string w = a[0]; + while (1) { + if (k) { + if (j == b.size()) { + return true; + } + if ((b[j][0] == w[0] && w < b[j]) || b[j][0] - w[0] == 1) { + w = b[j]; + k ^= 1; + } + ++j; + } else { + if (i == a.size()) { + return false; + } + if ((a[i][0] == w[0] && w < a[i]) || a[i][0] - w[0] == 1) { + w = a[i]; + k ^= 1; + } + ++i; + } + } + } +}; +``` + +### **Go** + +```go +func canAliceWin(a []string, b []string) bool { + i, j, k := 1, 0, 1 + w := a[0] + for { + if k&1 == 1 { + if j == len(b) { + return true + } + if (b[j][0] == w[0] && w < b[j]) || b[j][0]-w[0] == 1 { + w = b[j] + k ^= 1 + } + j++ + } else { + if i == len(a) { + return false + } + if (a[i][0] == w[0] && w < a[i]) || a[i][0]-w[0] == 1 { + w = a[i] + k ^= 1 + } + i++ + } + } +} +``` + +### **TypeScript** + +```ts +function canAliceWin(a: string[], b: string[]): boolean { + let [i, j, k] = [1, 0, 1]; + let w = a[0]; + while (1) { + if (k) { + if (j === b.length) { + return true; + } + if ((b[j][0] === w[0] && w < b[j]) || b[j].charCodeAt(0) - w.charCodeAt(0) === 1) { + w = b[j]; + k ^= 1; + } + ++j; + } else { + if (i === a.length) { + return false; + } + if ((a[i][0] === w[0] && w < a[i]) || a[i].charCodeAt(0) - w.charCodeAt(0) === 1) { + w = a[i]; + k ^= 1; + } + ++i; + } + } +} +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2868.The Wording Game/Solution.cpp b/solution/2800-2899/2868.The Wording Game/Solution.cpp new file mode 100644 index 0000000000000..6bc5d02410cf8 --- /dev/null +++ b/solution/2800-2899/2868.The Wording Game/Solution.cpp @@ -0,0 +1,28 @@ +class Solution { +public: + bool canAliceWin(vector& a, vector& b) { + int i = 1, j = 0, k = 1; + string w = a[0]; + while (1) { + if (k) { + if (j == b.size()) { + return true; + } + if ((b[j][0] == w[0] && w < b[j]) || b[j][0] - w[0] == 1) { + w = b[j]; + k ^= 1; + } + ++j; + } else { + if (i == a.size()) { + return false; + } + if ((a[i][0] == w[0] && w < a[i]) || a[i][0] - w[0] == 1) { + w = a[i]; + k ^= 1; + } + ++i; + } + } + } +}; \ No newline at end of file diff --git a/solution/2800-2899/2868.The Wording Game/Solution.go b/solution/2800-2899/2868.The Wording Game/Solution.go new file mode 100644 index 0000000000000..845f81374bfc7 --- /dev/null +++ b/solution/2800-2899/2868.The Wording Game/Solution.go @@ -0,0 +1,25 @@ +func canAliceWin(a []string, b []string) bool { + i, j, k := 1, 0, 1 + w := a[0] + for { + if k&1 == 1 { + if j == len(b) { + return true + } + if (b[j][0] == w[0] && w < b[j]) || b[j][0]-w[0] == 1 { + w = b[j] + k ^= 1 + } + j++ + } else { + if i == len(a) { + return false + } + if (a[i][0] == w[0] && w < a[i]) || a[i][0]-w[0] == 1 { + w = a[i] + k ^= 1 + } + i++ + } + } +} \ No newline at end of file diff --git a/solution/2800-2899/2868.The Wording Game/Solution.java b/solution/2800-2899/2868.The Wording Game/Solution.java new file mode 100644 index 0000000000000..54b56627d6f4d --- /dev/null +++ b/solution/2800-2899/2868.The Wording Game/Solution.java @@ -0,0 +1,28 @@ +class Solution { + public boolean canAliceWin(String[] a, String[] b) { + int i = 1, j = 0; + boolean k = true; + String w = a[0]; + while (true) { + if (k) { + if (j == b.length) { + return true; + } + if ((b[j].charAt(0) == w.charAt(0) && w.compareTo(b[j]) < 0) || b[j].charAt(0) - w.charAt(0) == 1) { + w = b[j]; + k = !k; + } + ++j; + } else { + if (i == a.length) { + return false; + } + if ((a[i].charAt(0) == w.charAt(0) && w.compareTo(a[i]) < 0) || a[i].charAt(0) - w.charAt(0) == 1) { + w = a[i]; + k = !k; + } + ++i; + } + } + } +} \ No newline at end of file diff --git a/solution/2800-2899/2868.The Wording Game/Solution.py b/solution/2800-2899/2868.The Wording Game/Solution.py new file mode 100644 index 0000000000000..01228cd9e6681 --- /dev/null +++ b/solution/2800-2899/2868.The Wording Game/Solution.py @@ -0,0 +1,19 @@ +class Solution: + def canAliceWin(self, a: List[str], b: List[str]) -> bool: + i, j, k = 1, 0, 1 + w = a[0] + while 1: + if k: + if j == len(b): + return True + if (b[j][0] == w[0] and b[j] > w) or ord(b[j][0]) - ord(w[0]) == 1: + w = b[j] + k ^= 1 + j += 1 + else: + if i == len(a): + return False + if (a[i][0] == w[0] and a[i] > w) or ord(a[i][0]) - ord(w[0]) == 1: + w = a[i] + k ^= 1 + i += 1 diff --git a/solution/2800-2899/2868.The Wording Game/Solution.ts b/solution/2800-2899/2868.The Wording Game/Solution.ts new file mode 100644 index 0000000000000..1e998645d05fe --- /dev/null +++ b/solution/2800-2899/2868.The Wording Game/Solution.ts @@ -0,0 +1,25 @@ +function canAliceWin(a: string[], b: string[]): boolean { + let [i, j, k] = [1, 0, 1]; + let w = a[0]; + while (1) { + if (k) { + if (j === b.length) { + return true; + } + if ((b[j][0] === w[0] && w < b[j]) || b[j].charCodeAt(0) - w.charCodeAt(0) === 1) { + w = b[j]; + k ^= 1; + } + ++j; + } else { + if (i === a.length) { + return false; + } + if ((a[i][0] === w[0] && w < a[i]) || a[i].charCodeAt(0) - w.charCodeAt(0) === 1) { + w = a[i]; + k ^= 1; + } + ++i; + } + } +} diff --git a/solution/README.md b/solution/README.md index 78653c199a950..d588236234918 100644 --- a/solution/README.md +++ b/solution/README.md @@ -2878,6 +2878,7 @@ | 2865 | [美丽塔 I](/solution/2800-2899/2865.Beautiful%20Towers%20I/README.md) | `栈`,`数组`,`单调栈` | 中等 | 第 364 场周赛 | | 2866 | [美丽塔 II](/solution/2800-2899/2866.Beautiful%20Towers%20II/README.md) | `栈`,`数组`,`单调栈` | 中等 | 第 364 场周赛 | | 2867 | [统计树中的合法路径数目](/solution/2800-2899/2867.Count%20Valid%20Paths%20in%20a%20Tree/README.md) | `树`,`深度优先搜索`,`数学`,`动态规划`,`数论` | 困难 | 第 364 场周赛 | +| 2868 | [单词游戏](/solution/2800-2899/2868.The%20Wording%20Game/README.md) | | 困难 | 🔒 | ## 版权 diff --git a/solution/README_EN.md b/solution/README_EN.md index 4d652c14748c7..bf63c7be8fa55 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -2876,6 +2876,7 @@ Press Control + F(or Command + F on | 2865 | [Beautiful Towers I](/solution/2800-2899/2865.Beautiful%20Towers%20I/README_EN.md) | `Stack`,`Array`,`Monotonic Stack` | Medium | Weekly Contest 364 | | 2866 | [Beautiful Towers II](/solution/2800-2899/2866.Beautiful%20Towers%20II/README_EN.md) | `Stack`,`Array`,`Monotonic Stack` | Medium | Weekly Contest 364 | | 2867 | [Count Valid Paths in a Tree](/solution/2800-2899/2867.Count%20Valid%20Paths%20in%20a%20Tree/README_EN.md) | `Tree`,`Depth-First Search`,`Math`,`Dynamic Programming`,`Number Theory` | Hard | Weekly Contest 364 | +| 2868 | [The Wording Game](/solution/2800-2899/2868.The%20Wording%20Game/README_EN.md) | | Hard | 🔒 | ## Copyright diff --git a/solution/summary.md b/solution/summary.md index de72a69fe3d7d..de6e3c4339afa 100644 --- a/solution/summary.md +++ b/solution/summary.md @@ -2923,3 +2923,4 @@ - [2865.美丽塔 I](/solution/2800-2899/2865.Beautiful%20Towers%20I/README.md) - [2866.美丽塔 II](/solution/2800-2899/2866.Beautiful%20Towers%20II/README.md) - [2867.统计树中的合法路径数目](/solution/2800-2899/2867.Count%20Valid%20Paths%20in%20a%20Tree/README.md) + - [2868.单词游戏](/solution/2800-2899/2868.The%20Wording%20Game/README.md) diff --git a/solution/summary_en.md b/solution/summary_en.md index e04529e6f0739..87ac5434ac6f0 100644 --- a/solution/summary_en.md +++ b/solution/summary_en.md @@ -2923,3 +2923,4 @@ - [2865.Beautiful Towers I](/solution/2800-2899/2865.Beautiful%20Towers%20I/README_EN.md) - [2866.Beautiful Towers II](/solution/2800-2899/2866.Beautiful%20Towers%20II/README_EN.md) - [2867.Count Valid Paths in a Tree](/solution/2800-2899/2867.Count%20Valid%20Paths%20in%20a%20Tree/README_EN.md) + - [2868.The Wording Game](/solution/2800-2899/2868.The%20Wording%20Game/README_EN.md) From 936225b4d2ada9f534183cc5dc2a7515b97bac74 Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Fri, 29 Sep 2023 03:05:02 +0000 Subject: [PATCH 2/2] fix: code style --- solution/2800-2899/2868.The Wording Game/README.md | 6 ++++-- solution/2800-2899/2868.The Wording Game/README_EN.md | 6 ++++-- solution/2800-2899/2868.The Wording Game/Solution.java | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/solution/2800-2899/2868.The Wording Game/README.md b/solution/2800-2899/2868.The Wording Game/README.md index 17e04c881932f..bf603ead8225c 100644 --- a/solution/2800-2899/2868.The Wording Game/README.md +++ b/solution/2800-2899/2868.The Wording Game/README.md @@ -141,7 +141,8 @@ class Solution { if (j == b.length) { return true; } - if ((b[j].charAt(0) == w.charAt(0) && w.compareTo(b[j]) < 0) || b[j].charAt(0) - w.charAt(0) == 1) { + if ((b[j].charAt(0) == w.charAt(0) && w.compareTo(b[j]) < 0) + || b[j].charAt(0) - w.charAt(0) == 1) { w = b[j]; k = !k; } @@ -150,7 +151,8 @@ class Solution { if (i == a.length) { return false; } - if ((a[i].charAt(0) == w.charAt(0) && w.compareTo(a[i]) < 0) || a[i].charAt(0) - w.charAt(0) == 1) { + if ((a[i].charAt(0) == w.charAt(0) && w.compareTo(a[i]) < 0) + || a[i].charAt(0) - w.charAt(0) == 1) { w = a[i]; k = !k; } diff --git a/solution/2800-2899/2868.The Wording Game/README_EN.md b/solution/2800-2899/2868.The Wording Game/README_EN.md index 00cf72015878e..2eb18c7fb57a6 100644 --- a/solution/2800-2899/2868.The Wording Game/README_EN.md +++ b/solution/2800-2899/2868.The Wording Game/README_EN.md @@ -120,7 +120,8 @@ class Solution { if (j == b.length) { return true; } - if ((b[j].charAt(0) == w.charAt(0) && w.compareTo(b[j]) < 0) || b[j].charAt(0) - w.charAt(0) == 1) { + if ((b[j].charAt(0) == w.charAt(0) && w.compareTo(b[j]) < 0) + || b[j].charAt(0) - w.charAt(0) == 1) { w = b[j]; k = !k; } @@ -129,7 +130,8 @@ class Solution { if (i == a.length) { return false; } - if ((a[i].charAt(0) == w.charAt(0) && w.compareTo(a[i]) < 0) || a[i].charAt(0) - w.charAt(0) == 1) { + if ((a[i].charAt(0) == w.charAt(0) && w.compareTo(a[i]) < 0) + || a[i].charAt(0) - w.charAt(0) == 1) { w = a[i]; k = !k; } diff --git a/solution/2800-2899/2868.The Wording Game/Solution.java b/solution/2800-2899/2868.The Wording Game/Solution.java index 54b56627d6f4d..078acb57be1c0 100644 --- a/solution/2800-2899/2868.The Wording Game/Solution.java +++ b/solution/2800-2899/2868.The Wording Game/Solution.java @@ -8,7 +8,8 @@ public boolean canAliceWin(String[] a, String[] b) { if (j == b.length) { return true; } - if ((b[j].charAt(0) == w.charAt(0) && w.compareTo(b[j]) < 0) || b[j].charAt(0) - w.charAt(0) == 1) { + if ((b[j].charAt(0) == w.charAt(0) && w.compareTo(b[j]) < 0) + || b[j].charAt(0) - w.charAt(0) == 1) { w = b[j]; k = !k; } @@ -17,7 +18,8 @@ public boolean canAliceWin(String[] a, String[] b) { if (i == a.length) { return false; } - if ((a[i].charAt(0) == w.charAt(0) && w.compareTo(a[i]) < 0) || a[i].charAt(0) - w.charAt(0) == 1) { + if ((a[i].charAt(0) == w.charAt(0) && w.compareTo(a[i]) < 0) + || a[i].charAt(0) - w.charAt(0) == 1) { w = a[i]; k = !k; }