Friday, January 28, 2022

OSCHINA 社区最新专区文章

OSCHINA 社区最新专区文章


LeetCode 17. 电话号码的字母组合

Posted: 28 Jan 2022 03:30 AM PST

具体思路: 典型的排列组合问题,需要注意一下递归写法; 具体代码: class Solution { public: vector<string>dic = { "","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; void fun(vector<string>& ret, int index, string digits,string now) { if (index == digits.size()) { ...

LeetCode 605. 种花问题

Posted: 28 Jan 2022 01:56 AM PST

基本思想: 注意特例,首尾添0最可靠; 具体代码: class Solution { public: bool canPlaceFlowers(vector<int>& flowerbed, int n) { int cnt = 0; int index = 0; flowerbed.insert(flowerbed.begin(),0); flowerbed.push_back(0); for (int i = 0; i < flowerb...

LeetCode 300. 最长递增子序列

Posted: 28 Jan 2022 01:36 AM PST

基本思路: 老生常谈的DP问题,没什么可说的,肌肉记忆; 具体代码: class Solution { public: int lengthOfLIS(vector<int>& nums) { if (nums.size() == 1) return 1; vector<int>dp(nums.size()); dp[0] = 1; for (int i = 1; i < nums.size(); i++) { ...

No comments:

Post a Comment