classSolution{publicStringlongestPalindrome(Strings){if(s==null||s.length()<1)return"";intstart=0;intend=0;for(inti=0;i<s.length();i++){intlen1=expandAroundCenter(s,i,i);//以一个字符为中心intlen2=expandAroundCenter(s,i
仓库的更新的大部分算法题都是通过 Java 语言解答的,少部分是使用 C/C++解答。 3.leetcode[3] 多种编程语言实现LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》题解。 4.LeetCode-Solution-in-Good-Style[4] 这个项目是作者在学习《算法与数据结构》的时候,在 LeetCode(力扣)[5] 上...
#TitleSolutionDifficultyAnalysis 306 Additive Number Java Medium 305 Number of Islands II Java Hard 304 Range Sum Query 2D - Immutable Java Medium 303 Range Sum Query - Immutable Java Easy 302 Smallest Rectangle Enclosing Black Pixels Java Medium 300 Longest Increasing Subsequence Java Medium...
packagecom.yang.test;importjava.util.Arrays;/*** @date 2021/1/1320:32*/publicclassSolution {publicstaticvoidmain(String[] arg0){int[][] edges =newint[][]{{1,2},{2,3},{3,4},{1,4},{2,4},{1,3}}; Solution solution=newSolution();int[] target =solution.findRedundantConnection(...
2.Solutions: 1/**2* Created by sheepcore on 2019-05-073*/4classSolution {5publicint[] dailyTemperatures(int[] T) {6int[] res =newint[T.length];7for(inti = 0; i < T.length -1; i++){8booleanhasWarmerDay =false;9for(intj = i + 1; j < T.length; j++){10if(T[i] <...
Code This branch is9026 commits behinddoocs/leetcode:main. README CC-BY-SA-4.0 license 介绍 本项目包含LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》等题目的相关题解。所有题解均由多种编程语言实现,包括但不限于:Java、Python、C++、JavaScript、C#、Go,日常更新。欢迎Star关注本...
from collectionsimportdefaultdictclassSolution:defmaxPoints(self,points):""":type points:List[Point]:rtype:int""" slopes,result=defaultdict(int),0fori,point1inenumerate(points):slopes.clear()duplicate=1for_,point2inenumerate(points[i+1:]):ifpoint1.x==point2.x and point1.y==point2.y:dup...
https://leetcode.cn/problems/binary-tree-inorder-traversal/ 给定一个二叉树的根节点 root ,返回 它的中序 遍历。 class Solution { public: void dfs(TreeNode* root,vector<int>& res){ if(root==NULL){return;} dfs(root->left,res); res.push_back(root->val); dfs(root->right,res); } ...
classSolution{public:vector<int>num;vector<int>preorder(Node*root){if(root==NULL)returnnum;//特例num.emplace_back(root->val);//加入元素//前序遍历for(Node*t:root->children){preorder(t);}returnnum;}}; 好了,今天的文章就到这里,如果觉得有所收获,请顺手点个在看或者转发吧,你们的支持是我...
Java语言实现代码 class Solution {//这个方法是判断是否为运算符的 private boolean isOperation(String x) {if(x.equals("+") || x.equals("-") || x.equals("*") || x.equals("/")) {return true; } return false; } public int evalRPN(String[] tokens) {Stack stack = new Stack(); ...