Problem: Solve a given equation and return the value of x in the form of string “x=#value”. The equation contains only ‘+’, ‘-’ operation, the variable x and its coefficient. If there is no solution for the equation, return “No solution”. If there are infinite solutions for ...
代码:(比较函数用了C++11中的lambda表达式) 1classSolution {2public:3vector<pair<int,int>> reconstructQueue(vector<pair<int,int>>&people) {4vector<pair<int,int>>result;5sort(people.begin(), people.end(), [](constpair<int,int>& p1,constpair<int,int>&p2)6{7if(p1.first ==p2.first)...
第一题 暴力草,没啥好说的。 class Solution { public: bool a[30], b[30]; string greatestLetter(string s) { for (auto x :s) { if (x >= 'a' && x <= 'z') a[x-'a'] = true; if (x >= 'A' && x <= 'Z') b[x-'A'] = true; } int ans = -1; for (int i =...
代码: 1classSolution {2public:3boolcanPartition(vector<int>&nums) {4intsum =0;5for(inti =0; i < nums.size(); ++i) {6sum +=nums[i];7}8if(sum %2==1) {9returnfalse;10}11sum /=2;12intdp[nums.size()][sum] = {false};13if(nums.size() ==1) {14returnfalse;15}16for(...
世界服448名,名次不行的主要原因是第三题做了太久,而且吃了一发WA。。 第一题 签到题,没啥好说的。实现的时候可以先不做除法,等到最后再除以100,避免浮点数误差累计。 class Solution { public: double calculateTax(vector<vector<int>>& brackets, int income) { double ans = 0; int last = 0; for...
classSolution:defoddString(self,words:List[str])->str:deffn(word):res=[]n=len(word)foriinrange(n-1):res.append(ord(word[i+1])-ord(word[i]))returntuple(res)cnt=defaultdict(int)forwinwords:cnt[fn(w)]+=1forwinwords:ifcnt[fn(w)]==1:returnw ...
LeetCode: Weekly Contest 98 题解列表 1. LeetCode: 888. Fair Candy Swap 题解 签到题。可以直接暴力求解。依次尝试交换任意两个 candy bar。 2. LeetCode: 890. Find and Replace Pattern 题解 对每个字符根据其出现顺序进行编号,然后将字符串用编号表示。如果编号表示的字符...
https://leetcode-cn.com/contest/weekly-contest-174/ranking/1/ 总体心得 使用python3,做成了第一道题,第二道题的解超时,便结束了第一次周赛。 下午看了排行榜靠前的参赛者代码,最快的在17分钟内就完赛了(使用python3),使用python3的和c++的数量几乎对半分。
leetcode competitive-programming codeforces hackerearth edu codeforces-solutions codechef-solutions leetcode-solution leetcode-weekly-contest cses codechef-easy leetcode-weekly cses-solutions codeforces-solutions-github codechef-practice-beginner Updated Jan 28, 2025 C++ anish...
具体来说,在我以前找工作前,我将剑指offer刷完三遍、LeetCode HoT 100 刷完 + 14个LeetCode 常规...