
Leetcode
唯一昵称真难
这个作者很懒,什么都没留下…
展开
-
LeetCode最大数值
LeetCode最大数值题意编写一个方法,找出两个数字a和b中最大的那一个。不得使用if-else或其他比较运算符。示例:输入: a = 1, b = 2输出: 2解析可以很简单的取巧直接使用Math.max(a,b)来解决。但是,内部实质还是用到if-else来处理。转换下思路,求最大值可以用如下公示:int sum = a + b;int abs = abs(a -...原创 2020-03-27 17:06:48 · 421 阅读 · 0 评论 -
Leetcode 1+2+…+n
题目如下解析本题的特殊之处在于不能使用特殊if ,循环迭代、以及乘法除法。如此一来无法是让我们用递归来做,主要是屏蔽if 这个判断条件,那么如何规避呢?很简单,大多数语言普遍支持的&& 短路,有着跟||类似的特性,前面为false,后面不再执行。func sumNums(n int) int { var f func(k int,ret *int) bool ...原创 2020-02-28 00:11:21 · 314 阅读 · 0 评论 -
【LeetCode】495. Teemo Attacking(提莫大魔王)
In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo’s attacking ascending time series towards Ashe and the poisoning tim...原创 2018-11-06 22:38:29 · 289 阅读 · 0 评论 -
【LeetCode】368. Largest Divisible Subset
Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies:Si % Sj = 0 or Sj % Si = 0.If there are multiple solutions, retu...原创 2018-11-07 22:31:28 · 171 阅读 · 0 评论 -
【LeetCode】373. Find K Pairs with Smallest Sums
373. Find K Pairs with Smallest SumsYou are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k.Define a pair (u,v) which consists of one element from the first array...原创 2018-11-13 17:42:09 · 398 阅读 · 0 评论 -
【LeetCode】284.Peeking Iterator
284.Peeking Iterator题目描述:Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation – it essentially peek() at the...原创 2018-11-08 14:23:39 · 170 阅读 · 0 评论 -
【Leetcode】583.Delete Operation for Two Strings
Delete Operation for Two StringsGiven two words word1 and word2, find the minimum number of steps required to make word1 and word2 the same, where in each step you can delete one character in either ...原创 2018-11-20 21:09:36 · 181 阅读 · 0 评论 -
【Leetcode】376. Wiggle Subsequence
Wiggle SubsequenceA sequence of numbers is called a wiggle sequence if the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exis...原创 2018-11-16 17:30:00 · 222 阅读 · 0 评论 -
【Leetcode】880. Decoded String at Index
Decoded String at IndexAn encoded string S is given. To find and write the decoded string to a tape, the encoded string is read one character at a time and the following steps are taken:If the c...原创 2018-11-19 22:07:35 · 674 阅读 · 0 评论 -
【LeetCode】 71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it. For example, path = "/home/", => "/home" path = "/a/./b/../../c/", => "/c" Corner Cases: Did you consider the case ...原创 2018-07-02 23:09:39 · 193 阅读 · 0 评论 -
【LeetCode】70. Climbing Stairs
You 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?解析:台阶问题,每次可以走一步或者两部,问第n个...原创 2018-07-02 23:45:08 · 119 阅读 · 0 评论 -
【LeetCode】377. Combination Sum IV
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target. 题解:通过数组中的元素进行组合,满足和等于target。每个元素可以重复利用。...原创 2018-07-03 11:01:35 · 190 阅读 · 0 评论 -
【Leetcode】78. Subsets
Given a set of distinct integers, nums, return all possible subsets (the power set). Note: The solution set must not contain duplicate subsets. 解法1:Bit Manipulation (位运算) 将数组中的元素下标构...原创 2018-07-04 22:17:42 · 180 阅读 · 0 评论 -
【LeetCode】201. Bitwise AND of Numbers Range
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers in this range, inclusive.解析: 大概意思是找出m,n 二进制表示数的最高位相同的位数11001 11010 11011 11100 结果...原创 2018-07-04 22:31:05 · 201 阅读 · 0 评论 -
【LeetCode】865. Smallest Subtree with all the Deepest Nodes
Given a binary tree rooted at root, the depth of each node is the shortest distance to the root.A node is deepest if it has the largest depth possible among any node in the entire tree.The subtree...原创 2018-08-04 17:40:08 · 310 阅读 · 0 评论 -
【LeetCode】783. Minimum Distance Between BST Nodes
Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree. Input: root = [4,2,6,1,3,null,null]Output: 1Expl...原创 2018-08-01 21:22:47 · 178 阅读 · 0 评论 -
【LeetCode】788. Rotated Digits
X is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from X. Each digit must be rotated - we cannot choose to leave it alone.A number...原创 2018-08-01 22:12:16 · 220 阅读 · 0 评论 -
【LeetCode】44.Wildcard Matching
这个道题的大意是:输入一个目标串:s ,以及一个匹配串:p,进行如下规则的匹配: 如果p中存在?,则可以匹配s中任意一个单个字符 如果p中存在*,则可以匹配s中任意一串连续的序列,包括空字符解法一:双指针 给定两个指针pIndex,sIndex。一个遍历p一个遍历s。当我们遍历时,会遇见如下的情况:当s[pIndex] == s[sIndex] 或者 ...原创 2018-06-13 22:29:21 · 224 阅读 · 0 评论