随笔分类 - 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;
阅读全文
摘要:!!!题目地址!!! int hammingWeight(uint32_t n) { int total = 0; for (int i = 0; i < 32; i++) { total += (n & 1); n = n >> 1; } return total; }
阅读全文
摘要:!!!题目地址!!! class Solution { public: double average(vector<int>& salary) { int maxNum = salary[0]; int minNum = salary[0]; int total = 0; for (int i =
阅读全文
摘要:!!!题目链接!!! class Solution { public: int countOdds(int low, int high) { return (high-low-high%2-low%2)/2 + high%2 + low%2; } };
阅读全文
摘要:!!!题目链接!!! Solution: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {}
阅读全文
摘要:!!!题目链接!!! 解决方案 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * Li
阅读全文
摘要:!!!题目链接!!! Solution: class Solution { public: string reverseWords(string s) { int le = s.size()-1; int ri = s.size()-1; reverse(s.begin(), s.end()); s
阅读全文
摘要:!!!题目链接!!! Solution: class Solution { public: void moveZeroes(vector<int>& nums) { int le = 0; int ri = 0; while(ri != nums.size()) { if(nums[ri] != 0
阅读全文
摘要:!!!题目链接!!! Solution: class Solution { public: vector<int> twoSum(vector<int>& numbers, int target) { int le = 0; int ri = numbers.size()-1; vector<int
阅读全文
摘要:!!!题目链接!!! Solution: class Solution { public: void moveZeroes(vector<int>& nums) { int le = 0; int ri = 0; while(ri != nums.size()) { if(nums[ri] != 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
阅读全文
摘要:!!!题目链接!!! Solution: class Solution { public: vector<int> sortedSquares(vector<int>& nums) { vector<int> result(nums.size()); int le = 0; int ri = num
阅读全文
摘要:!!!题目链接!!! Solution: class Solution { public: int searchInsert(vector<int>& nums, int target) { int max = nums.size() -1 ; int min = 0; int mid = 0; i
阅读全文
摘要:!!!题目链接!!! // The API isBadVersion is defined for you. // bool isBadVersion(int version); class Solution { public: int firstBadVersion(int n) { long r
阅读全文
摘要:!!!题目链接!!! solution: class Solution { public: int search(vector<int>& nums, int target) { int min = 0; int mid = nums.size()/2; int max = nums.size();
阅读全文
摘要:Question: Longest Substring Without Repeating Characters Example 1: Input: s = "abcabcbb" Output: 3 Explanation: The answer is "abc", with the length
阅读全文
摘要: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
阅读全文
摘要: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
阅读全文

浙公网安备 33010602011771号