06 2024 档案
摘要:242题思路就是分别遍历两个单词,统计字母数量看看是否一致。 1 class Solution { 2 public: 3 bool isAnagram(string s, string t) { 4 vector<int>tmp1(26); 5 int len1 = s.size(); 6 int
阅读全文
摘要:24题多个指针遍历即可,需要注意其中的衔接。 1 class Solution { 2 public: 3 ListNode* swapPairs(ListNode* head) { 4 if (head == NULL || head->next == NULL) { 5 return head;
阅读全文
摘要:203加一个头节点统一进行操作,很方便,最后提交的时候去掉头节点就好。 1 class Solution { 2 public: 3 ListNode* removeElements(ListNode* head, int val) { 4 //为了操作统一 还是整一个头出来比较合适 5 //依旧是
阅读全文
摘要:977题没什么好说的,找到中间第一个非负值,以此为起点向左、向右分别遍历即可。 1 class Solution { 2 public: 3 vector<int> sortedSquares(vector<int>& nums) { 4 //找到第一个非负值 然后依次比较填入新数组中 5 //注意
阅读全文
摘要:704题主要注意一下区间的设置,另外要记得更新mid值,不然会陷入死循环。 class Solution { public: int search (vector<int>& nums, int target) { int left = 0; int right = nums.size() - 1;
阅读全文