![](https://img-blog.csdnimg.cn/20201014180756757.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
loserChen.
这个作者很懒,什么都没留下…
展开
-
LeetCode不定时刷题——palindrome
Determine whether an integer is a palindrome. Do this without extra space.判断一个整型是否是回文,回文需要规避负数,以及小于10的正数,别的与之前的Reverse Number无异class Solution {public boolean isPalindrome(int x) { int result=0;...原创 2020-03-08 17:58:46 · 229 阅读 · 0 评论 -
LeetCode不定时刷题——LCP
Write a function to find the longest common prefix string amongst an array of strings.class Solution {public String longestCommonPrefix(String[] strs) { if(strs.length==0){ return ""; ...原创 2020-03-08 17:57:44 · 402 阅读 · 0 评论 -
LeetCode不定时刷题——Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all valid but...原创 2020-03-08 17:57:09 · 174 阅读 · 0 评论 -
LeetCode不定时刷题——Merge two sorted linked lists and return it as a new list
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * public class ...原创 2020-03-08 17:56:35 · 219 阅读 · 0 评论 -
LeetCode不定时刷题——Remove Duplicates
Given a sorted array, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by modifying the...原创 2020-03-08 17:55:56 · 260 阅读 · 0 评论 -
LeetCode不定时刷题——Implement strStr()
Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = “hello”, needle = “ll”Output: 2Example 2:In...原创 2020-03-08 17:55:20 · 153 阅读 · 0 评论 -
LeetCode不定时刷题——Reverse Interger
Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dealing with...原创 2020-03-08 17:54:48 · 154 阅读 · 0 评论 -
LeetCode不定时刷题——Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] has th...原创 2020-03-08 17:54:12 · 170 阅读 · 0 评论 -
LeetCode不定时刷题——Length of Last Word
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined...原创 2020-03-08 17:53:30 · 204 阅读 · 1 评论 -
LeetCode不定时刷题——Climbing Stairs
Climbing StairsYou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will...原创 2020-03-08 17:52:48 · 381 阅读 · 0 评论 -
LeetCode不定时刷题——Remove Duplicates from Sorted List
Remove Duplicates from Sorted ListGiven a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->...原创 2020-03-08 17:51:54 · 198 阅读 · 0 评论 -
LeetCode不定时刷题——Merge Sorted Array
Merge Sorted ArrayGiven two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n...原创 2020-03-08 17:51:18 · 237 阅读 · 0 评论 -
LeetCode不定时刷题——Same Tree
Same TreeGiven two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value....原创 2020-03-08 17:50:44 · 193 阅读 · 0 评论 -
LeetCode不定时刷题——Symmetric Tree
Symmetric TreeGiven a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \...原创 2020-03-08 17:49:56 · 185 阅读 · 0 评论 -
LeetCode不定时刷题——Convert Sorted Array to Binary Search Tree
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for a binary tree node. * public class T...原创 2020-03-08 17:49:13 · 187 阅读 · 0 评论 -
LeetCode不定时刷题——Ugly Number
Ugly NumberWrite a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ug...原创 2020-03-07 22:19:47 · 132 阅读 · 0 评论 -
LeetCode不定时刷题——Count Primes
Count PrimesDescription:Count the number of prime numbers less than a non-negative number, n.Solution:class Solution { public int countPrimes(int n) { if(n<3){ return 0;...原创 2020-03-07 22:19:14 · 144 阅读 · 0 评论 -
LeetCode不定时刷题——Balanced Binary Tree
Balanced Binary TreeGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of ever...原创 2020-03-07 22:18:27 · 141 阅读 · 0 评论 -
LeetCode不定时刷题——Add Two Numbers
Add Two NumbersYou are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numb...原创 2020-03-07 22:17:50 · 134 阅读 · 0 评论 -
LeetCode不定时刷题——Peak Finder
Peak Finder问题在一个数组中找一个peak,使之大于他的邻居即可。可假设数组两端为负无穷。具体描述A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return ...原创 2020-03-07 22:16:38 · 281 阅读 · 0 评论 -
LeetCode不定时刷题——Merge Two Sorted Lists
21. Merge Two Sorted Lists递归/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution {...原创 2020-01-23 16:56:41 · 168 阅读 · 0 评论 -
LeetCode不定时刷题——Valid_Parentheses
20. Valid Parentheses使用栈对于这种括号的匹配问题,我们很轻易的想到使用栈来进行相关的操作。class Solution { public boolean isValid(String s) { if (s.length()==0){ return true; } Stack<Char...原创 2020-01-23 16:54:58 · 159 阅读 · 0 评论 -
Leetcode不定时刷题-两数之和
1、两数之和暴力解class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { int i,j; for(i=0;i<nums.size();i++){ for(j=i+1;j<nums.size...原创 2019-09-04 19:18:04 · 260 阅读 · 0 评论