File tree Expand file tree Collapse file tree 6 files changed +402
-0
lines changed
Expand file tree Collapse file tree 6 files changed +402
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * @Author: LetMeFly
3+ * @Date: 2024-11-21 22:59:40
4+ * @LastEditors: LetMeFly.xyz
5+ * @LastEditTime: 2024-11-21 23:02:59
6+ */
7+ #ifdef _WIN32
8+ #include " _[1,2]toVector.h"
9+ #endif
10+
11+ // 开始看题
12+ // 开始解题
13+ class Solution {
14+ public:
15+ int finalPositionOfSnake (int n, vector<string>& commands) {
16+ int ans = 0 ;
17+ for (string& command : commands) {
18+ switch (command[0 ])
19+ {
20+ case ' U' :
21+ ans -= n;
22+ break ;
23+ case ' D' :
24+ ans += n;
25+ break ;
26+ case ' L' :
27+ ans--;
28+ break ;
29+ default : // 'R'
30+ ans++;
31+ break ;
32+ }
33+ }
34+ return ans;
35+ }
36+ };
Original file line number Diff line number Diff line change 1+ /*
2+ * @Author: LetMeFly
3+ * @Date: 2024-11-21 23:07:12
4+ * @LastEditors: LetMeFly.xyz
5+ * @LastEditTime: 2024-11-21 23:08:30
6+ */
7+ package main
8+
9+ func finalPositionOfSnake (n int , commands []string ) (ans int ) {
10+ for _ , c := range commands {
11+ switch c [0 ] {
12+ case 'U' :
13+ ans -= n ;
14+ case 'D' :
15+ ans += n ;
16+ case 'L' :
17+ ans -- ;
18+ case 'R' :
19+ ans ++ ;
20+ }
21+ }
22+ return
23+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * @Author: LetMeFly
3+ * @Date: 2024-11-21 23:05:25
4+ * @LastEditors: LetMeFly.xyz
5+ * @LastEditTime: 2024-11-21 23:06:44
6+ */
7+ class Solution {
8+ public int finalPositionOfSnake (int n , List <String > commands ) {
9+ int ans = 0 ;
10+ for (String c : commands ) {
11+ switch (c .charAt (0 )) {
12+ case 'U' :
13+ ans -= n ;
14+ break ;
15+ case 'D' :
16+ ans += n ;
17+ break ;
18+ case 'L' :
19+ ans --;
20+ break ;
21+ default :
22+ ans ++;
23+ break ;
24+ }
25+ }
26+ return ans ;
27+ }
28+ }
Original file line number Diff line number Diff line change 1+ '''
2+ Author: LetMeFly
3+ Date: 2024-11-21 23:04:02
4+ LastEditors: LetMeFly.xyz
5+ LastEditTime: 2024-11-21 23:04:09
6+ '''
7+ from typing import List
8+
9+ class Solution :
10+ def finalPositionOfSnake (self , n : int , commands : List [str ]) -> int :
11+ ans = 0
12+ for c in commands :
13+ if c [0 ] == 'U' :
14+ ans -= n
15+ elif c [0 ] == 'D' :
16+ ans += n
17+ elif c [0 ] == 'L' :
18+ ans -= 1
19+ else :
20+ ans += 1
21+ return ans
Original file line number Diff line number Diff line change 725725| 3242.设计相邻元素求和服务| 简单| <a href =" https://leetcode.cn/problems/design-neighbor-sum-service/solutions/ " target =" _blank " >题目地址</a >| <a href =" https://blog.letmefly.xyz/2024/11/11/LeetCode%203242.%E8%AE%BE%E8%AE%A1%E7%9B%B8%E9%82%BB%E5%85%83%E7%B4%A0%E6%B1%82%E5%92%8C%E6%9C%8D%E5%8A%A1/ " target =" _blank " >题解地址</a >| <a href =" https://letmefly.blog.csdn.net/article/details/143698347 " target =" _blank " >CSDN题解</a >| <a href =" https://leetcode.cn/problems/design-neighbor-sum-service/solutions/2985408/letmefly-3242she-ji-xiang-lin-yuan-su-qi-mc7m/ " target =" _blank " >LeetCode题解</a >|
726726| 3243.新增道路查询后的最短距离I| 中等| <a href =" https://leetcode.cn/problems/shortest-distance-after-road-addition-queries-i/solutions/ " target =" _blank " >题目地址</a >| <a href =" https://blog.letmefly.xyz/2024/11/19/LeetCode%203243.%E6%96%B0%E5%A2%9E%E9%81%93%E8%B7%AF%E6%9F%A5%E8%AF%A2%E5%90%8E%E7%9A%84%E6%9C%80%E7%9F%AD%E8%B7%9D%E7%A6%BBI/ " target =" _blank " >题解地址</a >| <a href =" https://letmefly.blog.csdn.net/article/details/143897977 " target =" _blank " >CSDN题解</a >| <a href =" https://leetcode.cn/problems/shortest-distance-after-road-addition-queries-i/solutions/2994264/letmefly-3243xin-zeng-dao-lu-cha-xun-hou-3k6p/ " target =" _blank " >LeetCode题解</a >|
727727| 3244.新增道路查询后的最短距离II| 困难| <a href =" https://leetcode.cn/problems/shortest-distance-after-road-addition-queries-ii/solutions/ " target =" _blank " >题目地址</a >| <a href =" https://blog.letmefly.xyz/2024/11/20/LeetCode%203244.%E6%96%B0%E5%A2%9E%E9%81%93%E8%B7%AF%E6%9F%A5%E8%AF%A2%E5%90%8E%E7%9A%84%E6%9C%80%E7%9F%AD%E8%B7%9D%E7%A6%BBII/ " target =" _blank " >题解地址</a >| <a href =" https://letmefly.blog.csdn.net/article/details/143908539 " target =" _blank " >CSDN题解</a >| <a href =" https://leetcode.cn/problems/shortest-distance-after-road-addition-queries-ii/solutions/2994690/letmefly-3244xin-zeng-dao-lu-cha-xun-hou-7tna/ " target =" _blank " >LeetCode题解</a >|
728+ | 3248.矩阵中的蛇| 简单| <a href =" https://leetcode.cn/problems/snake-in-matrix/solutions/ " target =" _blank " >题目地址</a >| <a href =" https://blog.letmefly.xyz/2024/11/21/LeetCode%203248.%E7%9F%A9%E9%98%B5%E4%B8%AD%E7%9A%84%E8%9B%87/ " target =" _blank " >题解地址</a >| <a href =" https://letmefly.blog.csdn.net/article/details/143957408 " target =" _blank " >CSDN题解</a >| <a href =" https://leetcode.cn/problems/snake-in-matrix/solutions/2996578/letmefly-3248ju-zhen-zhong-de-she-mo-ni-ttfkl/ " target =" _blank " >LeetCode题解</a >|
728729| 3249.统计好节点的数目| 中等| <a href =" https://leetcode.cn/problems/count-the-number-of-good-nodes/solutions/ " target =" _blank " >题目地址</a >| <a href =" https://blog.letmefly.xyz/2024/11/14/LeetCode%203249.%E7%BB%9F%E8%AE%A1%E5%A5%BD%E8%8A%82%E7%82%B9%E7%9A%84%E6%95%B0%E7%9B%AE/ " target =" _blank " >题解地址</a >| <a href =" https://letmefly.blog.csdn.net/article/details/143768804 " target =" _blank " >CSDN题解</a >| <a href =" https://leetcode.cn/problems/count-the-number-of-good-nodes/solutions/2988295/letmefly-3249tong-ji-hao-jie-dian-de-shu-zojm/ " target =" _blank " >LeetCode题解</a >|
729730| 3254.长度为K的子数组的能量值I| 中等| <a href =" https://leetcode.cn/problems/find-the-power-of-k-size-subarrays-i/solutions/ " target =" _blank " >题目地址</a >| <a href =" https://blog.letmefly.xyz/2024/11/06/LeetCode%203254.%E9%95%BF%E5%BA%A6%E4%B8%BAK%E7%9A%84%E5%AD%90%E6%95%B0%E7%BB%84%E7%9A%84%E8%83%BD%E9%87%8F%E5%80%BCI/ " target =" _blank " >题解地址</a >| <a href =" https://letmefly.blog.csdn.net/article/details/143575677 " target =" _blank " >CSDN题解</a >| <a href =" https://leetcode.cn/problems/find-the-power-of-k-size-subarrays-i/solutions/2979562/letmefly-3254chang-du-wei-k-de-zi-shu-zu-iu8u/ " target =" _blank " >LeetCode题解</a >|
730731| 3255.长度为K的子数组的能量值II| 中等| <a href =" https://leetcode.cn/problems/find-the-power-of-k-size-subarrays-ii/solutions/ " target =" _blank " >题目地址</a >| <a href =" https://blog.letmefly.xyz/2024/11/07/LeetCode%203255.%E9%95%BF%E5%BA%A6%E4%B8%BAK%E7%9A%84%E5%AD%90%E6%95%B0%E7%BB%84%E7%9A%84%E8%83%BD%E9%87%8F%E5%80%BCII/ " target =" _blank " >题解地址</a >| <a href =" https://letmefly.blog.csdn.net/article/details/143591327 " target =" _blank " >CSDN题解</a >| <a href =" https://leetcode.cn/problems/find-the-power-of-k-size-subarrays-ii/solutions/2980432/letmefly-3255chang-du-wei-k-de-zi-shu-zu-rags/ " target =" _blank " >LeetCode题解</a >|
You can’t perform that action at this time.
0 commit comments