随笔分类 -  Leetcode

摘要:111. 二叉树的最小深度 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), 阅读全文
posted @ 2020-11-23 12:51 五岁就很帅🎈 阅读(124) 评论(0) 推荐(0)
摘要: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; 阅读全文
posted @ 2020-11-23 12:50 五岁就很帅🎈 阅读(107) 评论(0) 推荐(0)
摘要:71. 简化路径 class Solution { public: string simplifyPath(string path) { string res, name; if (path.back() != '/') path += '/'; for (auto c : path) { if ( 阅读全文
posted @ 2020-11-23 12:49 五岁就很帅🎈 阅读(92) 评论(0) 推荐(0)
摘要:51. N 皇后 class Solution { public: vector<vector<string>> ans; vector<string> path; vector<bool> row, col, diag, anti_diag; vector<vector<string>> solv 阅读全文
posted @ 2020-11-23 12:47 五岁就很帅🎈 阅读(94) 评论(0) 推荐(0)
摘要:31. 下一个排列 class Solution { public: void nextPermutation(vector<int>& nums) { int k = nums.size() - 1; while (k > 0 && nums[k - 1] >= nums[k]) k -- ; i 阅读全文
posted @ 2020-11-23 12:46 五岁就很帅🎈 阅读(83) 评论(0) 推荐(0)
摘要: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, 阅读全文
posted @ 2020-11-23 12:45 五岁就很帅🎈 阅读(55) 评论(0) 推荐(0)
摘要: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; 阅读全文
posted @ 2020-11-23 12:42 五岁就很帅🎈 阅读(75) 评论(0) 推荐(0)