diff --git a/solution/3300-3399/3307.Find the K-th Character in String Game II/README.md b/solution/3300-3399/3307.Find the K-th Character in String Game II/README.md index 5065706f87f45..b2a5316dfdbeb 100644 --- a/solution/3300-3399/3307.Find the K-th Character in String Game II/README.md +++ b/solution/3300-3399/3307.Find the K-th Character in String Game II/README.md @@ -251,6 +251,61 @@ impl Solution { } ``` +#### C# + +```cs +public class Solution { + public char KthCharacter(long k, int[] operations) { + long n = 1; + int i = 0; + while (n < k) { + n *= 2; + ++i; + } + int d = 0; + while (n > 1) { + if (k > n / 2) { + k -= n / 2; + d += operations[i - 1]; + } + n /= 2; + --i; + } + return (char)('a' + (d % 26)); + } +} +``` + +#### PHP + +```php +class Solution { + /** + * @param Integer $k + * @param Integer[] $operations + * @return String + */ + function kthCharacter($k, $operations) { + $n = 1; + $i = 0; + while ($n < $k) { + $n *= 2; + ++$i; + } + $d = 0; + while ($n > 1) { + if ($k > $n / 2) { + $k -= $n / 2; + $d += $operations[$i - 1]; + } + $n /= 2; + --$i; + } + return chr(ord('a') + ($d % 26)); + } +} +``` + diff --git a/solution/3300-3399/3307.Find the K-th Character in String Game II/README_EN.md b/solution/3300-3399/3307.Find the K-th Character in String Game II/README_EN.md index 3ead9e974af75..f8ad4b7e28c7b 100644 --- a/solution/3300-3399/3307.Find the K-th Character in String Game II/README_EN.md +++ b/solution/3300-3399/3307.Find the K-th Character in String Game II/README_EN.md @@ -248,6 +248,61 @@ impl Solution { } ``` +#### C# + +```cs +public class Solution { + public char KthCharacter(long k, int[] operations) { + long n = 1; + int i = 0; + while (n < k) { + n *= 2; + ++i; + } + int d = 0; + while (n > 1) { + if (k > n / 2) { + k -= n / 2; + d += operations[i - 1]; + } + n /= 2; + --i; + } + return (char)('a' + (d % 26)); + } +} +``` + +#### PHP + +```php +class Solution { + /** + * @param Integer $k + * @param Integer[] $operations + * @return String + */ + function kthCharacter($k, $operations) { + $n = 1; + $i = 0; + while ($n < $k) { + $n *= 2; + ++$i; + } + $d = 0; + while ($n > 1) { + if ($k > $n / 2) { + $k -= $n / 2; + $d += $operations[$i - 1]; + } + $n /= 2; + --$i; + } + return chr(ord('a') + ($d % 26)); + } +} +``` + diff --git a/solution/3300-3399/3307.Find the K-th Character in String Game II/Solution.cs b/solution/3300-3399/3307.Find the K-th Character in String Game II/Solution.cs new file mode 100644 index 0000000000000..e5b4528c3de93 --- /dev/null +++ b/solution/3300-3399/3307.Find the K-th Character in String Game II/Solution.cs @@ -0,0 +1,20 @@ +public class Solution { + public char KthCharacter(long k, int[] operations) { + long n = 1; + int i = 0; + while (n < k) { + n *= 2; + ++i; + } + int d = 0; + while (n > 1) { + if (k > n / 2) { + k -= n / 2; + d += operations[i - 1]; + } + n /= 2; + --i; + } + return (char)('a' + (d % 26)); + } +} diff --git a/solution/3300-3399/3307.Find the K-th Character in String Game II/Solution.php b/solution/3300-3399/3307.Find the K-th Character in String Game II/Solution.php new file mode 100644 index 0000000000000..7c56a34a4d892 --- /dev/null +++ b/solution/3300-3399/3307.Find the K-th Character in String Game II/Solution.php @@ -0,0 +1,25 @@ +class Solution { + /** + * @param Integer $k + * @param Integer[] $operations + * @return String + */ + function kthCharacter($k, $operations) { + $n = 1; + $i = 0; + while ($n < $k) { + $n *= 2; + ++$i; + } + $d = 0; + while ($n > 1) { + if ($k > $n / 2) { + $k -= $n / 2; + $d += $operations[$i - 1]; + } + $n /= 2; + --$i; + } + return chr(ord('a') + ($d % 26)); + } +} \ No newline at end of file diff --git a/solution/3600-3699/3601.Find Drivers with Improved Fuel Efficiency/README.md b/solution/3600-3699/3601.Find Drivers with Improved Fuel Efficiency/README.md index 77f86b85e4aa2..6ff91ebff701d 100644 --- a/solution/3600-3699/3601.Find Drivers with Improved Fuel Efficiency/README.md +++ b/solution/3600-3699/3601.Find Drivers with Improved Fuel Efficiency/README.md @@ -8,7 +8,7 @@ tags: -# [3601. Find Drivers with Improved Fuel Efficiency](https://leetcode.cn/problems/find-drivers-with-improved-fuel-efficiency) +# [3601. 寻找燃油效率提升的驾驶员](https://leetcode.cn/problems/find-drivers-with-improved-fuel-efficiency) [English Version](/solution/3600-3699/3601.Find%20Drivers%20with%20Improved%20Fuel%20Efficiency/README_EN.md) @@ -16,7 +16,7 @@ tags: -
Table: drivers
表:drivers
+-------------+---------+ @@ -25,11 +25,11 @@ tags: | driver_id | int | | driver_name | varchar | +-------------+---------+ -driver_id is the unique identifier for this table. -Each row contains information about a driver. +driver_id 是这张表的唯一主键。 +每一行都包含一个司机的信息。-
Table: trips
表:trips
+---------------+---------+ @@ -41,31 +41,32 @@ Each row contains information about a driver. | distance_km | decimal | | fuel_consumed | decimal | +---------------+---------+ -trip_id is the unique identifier for this table. -Each row represents a trip made by a driver, including the distance traveled and fuel consumed for that trip. +trip_id 是这张表的唯一主键。 +每一行表示一名司机完成的一次行程,包括该次行程行驶的距离和消耗的燃油量。-
Write a solution to find drivers whose fuel efficiency has improved by comparing their average fuel efficiency in the first half of the year with the second half of the year.
+编写一个解决方案,通过 比较 司机在 上半年 和 下半年 的 平均燃油效率 来找出 燃油效率有所提高 的司机。
distance_km / fuel_consumed
for each tripsecond_half_avg - first_half_avg
)2
decimal placesdistance_km / fuel_consumed
计算 每次 行程的 燃油效率。second_half_avg - first_half_avg
)计算 提升效率。2
位Return the result table ordered by efficiency improvement in descending order, then by driver name in ascending order.
+返回结果表按提升效率 降序 排列,然后按司机姓名 升序 排列。
-The result format is in the following example.
+结果格式如下所示。
-
Example:
+ +示例:
Input:
+输入:
-drivers table:
+drivers 表:
+-----------+---------------+ @@ -79,7 +80,7 @@ Each row represents a trip made by a driver, including the distance traveled and +-----------+---------------+-
trips table:
+trips 表:
+---------+-----------+------------+-------------+---------------+ @@ -100,7 +101,7 @@ Each row represents a trip made by a driver, including the distance traveled and +---------+-----------+------------+-------------+---------------+-
Output:
+输出:
+-----------+---------------+------------------+-------------------+------------------------+ @@ -111,39 +112,39 @@ Each row represents a trip made by a driver, including the distance traveled and +-----------+---------------+------------------+-------------------+------------------------+-
Explanation:
+解释:
The output table is ordered by efficiency improvement in descending order then by name in ascending order.
+输出表按提升效率降序排列,然后按司机名字升序排列。