随笔分类 -  Leetcode

Leetcode解题笔记
摘要:!!!题目地址!!! int subtractProductAndSum(int n){ int product = 1; int sum = 0; while(n != 0){ product *= n%10; sum += n%10; n /= 10; } return product-sum; 阅读全文
posted @ 2022-05-18 00:37 ReaIms 阅读(38) 评论(0) 推荐(0)
摘要:!!!题目地址!!! int hammingWeight(uint32_t n) { int total = 0; for (int i = 0; i < 32; i++) { total += (n & 1); n = n >> 1; } return total; } 阅读全文
posted @ 2022-05-18 00:31 ReaIms 阅读(20) 评论(0) 推荐(0)
摘要:!!!题目地址!!! class Solution { public: double average(vector<int>& salary) { int maxNum = salary[0]; int minNum = salary[0]; int total = 0; for (int i = 阅读全文
posted @ 2022-05-17 23:47 ReaIms 阅读(39) 评论(0) 推荐(0)
摘要:!!!题目链接!!! class Solution { public: int countOdds(int low, int high) { return (high-low-high%2-low%2)/2 + high%2 + low%2; } }; 阅读全文
posted @ 2022-05-17 23:17 ReaIms 阅读(26) 评论(0) 推荐(0)
摘要:!!!题目链接!!! Solution: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} 阅读全文
posted @ 2022-01-08 23:31 ReaIms 阅读(33) 评论(0) 推荐(0)
摘要:!!!题目链接!!! 解决方案 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * Li 阅读全文
posted @ 2022-01-07 07:12 ReaIms 阅读(39) 评论(0) 推荐(0)
摘要:!!!题目链接!!! Solution: class Solution { public: string reverseWords(string s) { int le = s.size()-1; int ri = s.size()-1; reverse(s.begin(), s.end()); s 阅读全文
posted @ 2022-01-07 06:05 ReaIms 阅读(47) 评论(0) 推荐(0)
摘要:!!!题目链接!!! Solution: class Solution { public: void moveZeroes(vector<int>& nums) { int le = 0; int ri = 0; while(ri != nums.size()) { if(nums[ri] != 0 阅读全文
posted @ 2022-01-07 03:55 ReaIms 阅读(53) 评论(0) 推荐(0)
摘要:!!!题目链接!!! Solution: class Solution { public: vector<int> twoSum(vector<int>& numbers, int target) { int le = 0; int ri = numbers.size()-1; vector<int 阅读全文
posted @ 2022-01-07 03:45 ReaIms 阅读(41) 评论(0) 推荐(0)
摘要:!!!题目链接!!! Solution: class Solution { public: void moveZeroes(vector<int>& nums) { int le = 0; int ri = 0; while(ri != nums.size()) { if(nums[ri] != 0 阅读全文
posted @ 2022-01-07 03:20 ReaIms 阅读(41) 评论(0) 推荐(0)
摘要:!!!题目链接!!! Solution: class Solution { public: void rotate(vector<int>& nums, int k) { vector<int> result(0); if(k > nums.size()) k = k%nums.size(); re 阅读全文
posted @ 2022-01-06 23:55 ReaIms 阅读(44) 评论(0) 推荐(0)
摘要:!!!题目链接!!! Solution: class Solution { public: vector<int> sortedSquares(vector<int>& nums) { vector<int> result(nums.size()); int le = 0; int ri = num 阅读全文
posted @ 2022-01-06 23:21 ReaIms 阅读(31) 评论(0) 推荐(0)
摘要:!!!题目链接!!! Solution: class Solution { public: int searchInsert(vector<int>& nums, int target) { int max = nums.size() -1 ; int min = 0; int mid = 0; i 阅读全文
posted @ 2022-01-05 10:35 ReaIms 阅读(63) 评论(0) 推荐(0)
摘要:!!!题目链接!!! // The API isBadVersion is defined for you. // bool isBadVersion(int version); class Solution { public: int firstBadVersion(int n) { long r 阅读全文
posted @ 2022-01-05 09:59 ReaIms 阅读(55) 评论(0) 推荐(0)
摘要:!!!题目链接!!! solution: class Solution { public: int search(vector<int>& nums, int target) { int min = 0; int mid = nums.size()/2; int max = nums.size(); 阅读全文
posted @ 2022-01-05 06:43 ReaIms 阅读(53) 评论(0) 推荐(0)
摘要:Question: Longest Substring Without Repeating Characters Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length 阅读全文
posted @ 2021-12-13 00:44 ReaIms 阅读(53) 评论(0) 推荐(0)
摘要:Question: Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume tha 阅读全文
posted @ 2021-12-12 07:16 ReaIms 阅读(73) 评论(0) 推荐(0)
摘要:Question: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their n 阅读全文
posted @ 2021-12-12 05:58 ReaIms 阅读(144) 评论(0) 推荐(0)