11 2020 档案
摘要:剑指 Offer 03. 数组中重复的数字 思路:将数组进行排序,这样数组是一个有序的序列,然后判断两个相邻的数是否相等,是则返回相同的数 时间复杂度:O(nlogn) class Solution { public: int findRepeatNumber(vector<int>& nums)
阅读全文
摘要:111. 二叉树的最小深度 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x),
阅读全文
摘要:91. 解码方法 class Solution { public: int numDecodings(string s) { int n = s.size(); s = ' ' + s; vector<int> f(n + 1); f[0] = 1; for (int i = 1; i <= n;
阅读全文
摘要:71. 简化路径 class Solution { public: string simplifyPath(string path) { string res, name; if (path.back() != '/') path += '/'; for (auto c : path) { if (
阅读全文
摘要:51. N 皇后 class Solution { public: vector<vector<string>> ans; vector<string> path; vector<bool> row, col, diag, anti_diag; vector<vector<string>> solv
阅读全文
摘要:31. 下一个排列 class Solution { public: void nextPermutation(vector<int>& nums) { int k = nums.size() - 1; while (k > 0 && nums[k - 1] >= nums[k]) k -- ; i
阅读全文
摘要:11. 盛最多水的容器 class Solution { public: int maxArea(vector<int>& height) { int res = 0; for (int i = 0, j = height.size() - 1; i < j; ) { res = max(res,
阅读全文
摘要:1. 两数之和 class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> v; for(int i = 0;i < nums.size();i++){ for(int j = i;
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; #define max(x,y) ((x) >
阅读全文

浙公网安备 33010602011771号