自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

dasdwaerqw

Remember so much time you wasted

  • 博客(48)
  • 收藏
  • 关注

转载 转载:刷题各个阶段的意义+Tips

为什么要刷题? 我想大部分new grad对这个问题没有任何疑惑。但对于已经有很多年工作经验的人,这个问题是一个必须想明白的问题。否则会极大的影响自己刷题的motivation.一边刷,一边愤恨道:我N年的经验根本不看,就考这些破算法题?你们谁工作用过这么复杂的算法?报着这个心理刷题,能刷成啥样可想而知。 做题和工作经验的关系,可以类比成下面这个问题:“男人看女人,到底是更看重外貌还是思想...

2018-08-07 16:30:33 406 1

翻译 当我们谈论刷题的时候,我们在谈论什么

刷题是一场一千五百米长跑。成败从不取决于你在某个时间节点的速度,而是全程的节奏感。之前两次刷题都是因为触发了严重的情绪焦虑没能坚持下来,直到看到这个问题的高票回答(https://www.zhihu.com/question/20571226)让我了解到不同的情绪分区:舒适区/学习区/焦虑区。你看着一道题不会打开参考程序看一行抄一行,感觉自己好像理解了这道题,全程非常舒适然而效果不大。再看到这道题...

2018-08-07 16:28:42 244

原创 Why do we insist? 打卡

刷题应该piecemeal,尽量早开始,坚持到退休。这个是吃饭的手艺,就像witcher的剑;一个猎魔人可以不吃饭,不睡觉,但不能不时时擦拭自己的剑。

2018-08-06 10:30:35 133

原创 849. Maximize Distance to Closest Person

class Solution { public int maxDistToClosest(int[] seats) { int i, j, res = 0, n = seats.length; for (i = j = 0; j < n; ++j) if (seats[j] == 1) { ...

2018-09-24 13:54:54 178

原创 747. Largest Number At Least Twice of Others

class Solution { public int dominantIndex(int[] nums) { int max = 0 ; for(int i = 0 ; i < nums.length; i++){ if(nums[i] > nums[max]...

2018-09-24 13:53:32 198

原创 448. Find All Numbers Disappeared in an Array

class Solution { public List<Integer> findDisappearedNumbers(int[] nums) { List<Integer> list = new ArrayList(); for(int x: nums){ int val = Math.abs(x) ...

2018-09-14 06:17:50 189

原创 888. Fair Candy Swap

class Solution { public int[] fairCandySwap(int[] A, int[] B) { //The mathmatics way we have is: // y = x + (SumB - SumA) / 2 int sumA = 0, sumB = 0; for(int x: ...

2018-09-14 04:52:54 142

原创 724. Find Pivot Index

class Solution { public int pivotIndex(int[] nums) { int leftsum = 0, sum = 0; //get the sum first, then check if the leftsum is equal to the rest of the array for(int i ...

2018-09-13 10:41:35 800

原创 896. Monotonic Array

class Solution { public boolean isMonotonic(int[] A) { return isIncreasing(A) || isDecreasing(A); } public boolean isIncreasing(int[] A){ for(int i = 0 ; i < A.lengt...

2018-09-13 10:39:57 271

原创 557. Reverse Words in a String III

给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序。示例 1:输入: “Let’s take LeetCode contest” 输出: “s’teL ekat edoCteeL tsetnoc” 注意:在字符串中,每个单词由单个空格分隔,并且字符串中不会有任何额外的空格。class Solution { public String ...

2018-08-18 16:03:21 447

原创 459. Repeated Substring Pattern

给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成。给定的字符串只含有小写英文字母,并且长度不超过10000。示例 1:输入: “abab”输出: True解释: 可由子字符串 “ab” 重复两次构成。 示例 2:输入: “aba”输出: False 示例 3:输入: “abcabcabcabc”输出: True解释: 可由子字符串 “abc” ...

2018-08-17 10:48:33 280

原创 387. First Unique Character in a String

string leetcode 的话 第一个唯一字符是l, return index 0; blaheblahd的话 return index 4;class Solution { public int firstUniqChar(String s) { int[] a = new int[26]; //26个字母 for(int i = 0;...

2018-08-15 18:01:20 128

原创 383. Ransom Note

题目要求找出magazine中是否有足够的字符for ransomnote,有则true 没则false;重复的字母magazine也需要提供class Solution { public boolean canConstruct(String ransomNote, String magazine) { if(ransomNote.length() > mag...

2018-08-15 12:30:37 117

原创 521. Longest Uncommon Subsequence I

给定两个字符串,你需要从这两个字符串中找出最长的特殊序列。最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列)。子序列可以通过删去字符串中的某些字符实现,但不能改变剩余字符的相对顺序。空序列为所有字符串的子序列,任何字符串为其自身的子序列。输入为两个字符串,输出最长特殊序列的长度。如果不存在,则返回 -1。示例 :输入: “aba”, “cdc” ...

2018-08-15 11:12:49 700

原创 434. Number of Segments in a String

统计字符串中的单词个数,这里的单词指的是连续的不是空格的字符。请注意,你可以假定字符串里不包括任何不可打印的字符。示例:输入: “Hello, my name is John” 输出: 5打完,!*这些特殊符号之后都会有个空格所以不用管,只算空格就otmk,此题题意有点trickyclass Solution { public int countSegments(St...

2018-08-15 10:41:30 141

原创 345. Reverse Vowels of a String

编写一个函数,以字符串作为输入,反转该字符串中的元音字母。示例 1:输入: “hello” 输出: “holle” 示例 2:输入: “leetcode” 输出: “leotcede” 说明: 元音字母不包含字母”y”。考察双指针class Solution { public String reverseVowels(String s) { ...

2018-08-15 09:46:36 145

原创 520. Detect Capital

检测要求的string以下三种情况 valid,其余的情况返回false:GooglegoogleGOOGLEclass Solution { public boolean detectCapitalUse(String word) { char[] words = word.toCharArray(); int allupper...

2018-08-14 20:57:31 126

原创 551. Student Attendance Record I

找出input string中,如果有大于一个‘A‘和大于两个连续的‘L‘,则返回false;else return trueclass Solution { public boolean checkRecord(String s) { int maxabs = 0, maxlate = 0; for(int i = 0 ; i ...

2018-08-14 19:19:51 122

原创 788. Rotate Number

我们称一个数 X 为好数, 如果它的每位数字逐个地被旋转 180 度后,我们仍可以得到一个有效的,且和 X 不同的数。要求每位数字都要被旋转。如果一个数的每位数字被旋转以后仍然还是一个数字, 则这个数是有效的。0, 1, 和 8 被旋转后仍然是它们自己;2 和 5 可以互相旋转成对方;6 和 9 同理,除了这些以外其他的数字旋转以后都不再是有效的数字。现在我们有一个正整数 N, 计算从 1...

2018-08-14 18:24:44 551

原创 412. Fizz Buzz

写一个程序,输出从 1 到 n 数字的字符串表示。如果 n 是3的倍数,输出“Fizz”;如果 n 是5的倍数,输出“Buzz”;3.如果 n 同时是3和5的倍数,输出 “FizzBuzz”。class Solution { public List<String> fizzBuzz(int n) { List<String> ...

2018-08-14 11:28:54 113

原创 415. Add Strings

Similar to binary add.Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is < 5100. Both num1 and num2 ...

2018-08-14 10:52:20 107

原创 414. Third Maximum Number

Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).Example 1:Input: [3, 2, 1]...

2018-08-14 07:07:10 99

原创 500. Keyboard Row

此题要求在input string array中找出能被一行键盘打出来的string,很有意思的一题,有很多amazing的解法:Solution 1:一行函数解爆它public String[] findWords(String[] words) { return Stream.of(words).filter(s -> s.toLowerCase().matches("[...

2018-08-13 14:37:33 127

原创 217. Contains Duplicate

原题   Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every elem...

2018-08-12 16:01:01 122

原创 485. Max Consecutive Ones

Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive ...

2018-08-11 21:06:19 111

原创 136. Single Number

题目: Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ...

2018-08-11 21:04:32 91

原创 268. Missing Number

题目:Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2.Note: Your algorithm should r...

2018-08-11 19:39:52 106

原创 561. Array Partition I

题目描述: Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large a...

2018-08-11 19:05:57 100

原创 283. Move Zeroes

题目 283.MoveZeroes Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements. For example, given nums = [0, 1, 0, 3, 12]...

2018-08-11 18:29:52 85

原创 628. Maximum Product of Three Numbers

问题描述:  Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:   Input: [1,2,3]   Output: 6 Example 2:   Input: [1,2,3,4]   Output: ...

2018-08-11 16:43:14 92

原创 学习材料

学链表很好的link:https://blog.csdn.net/u011910350/article/details/70993381

2018-08-10 18:10:59 93

原创 关于算法的一点总结

分解问题的角度: fix 某一维度,尝试另一维度上的所有可能 a. 可能是array的(i, j)pointers, b. 可能是矩形的长与宽, c. 可能是tree的每一个subtree, d. 可能是情景题的每一对pair… 求所有解的, 暴力上backtracking吧如果问最短/最少的, 先想BFS、DP这对好基友如果环相关/重复访问, DFS + visited state雄起...

2018-08-10 15:33:42 205

原创 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?uncompleted

2018-08-10 15:31:44 96

原创 67. Add Binary

Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”.class Solution { public String addBinary(String a, String b) { String...

2018-08-09 17:34:38 79

原创 66. Plus One

Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits a...

2018-08-08 18:10:21 86

原创 58. 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 defin...

2018-08-07 21:01:05 85

原创 53. 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 ...

2018-08-07 20:16:03 86

原创 20. Valid Parentheses

Given a string containing justthe characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[’ and ‘]’, determine if the input string is valid. The brackets must close in the correct order, “()” and “()[]{}” are all valid but...

2018-08-07 17:16:06 83

原创 852. Peak Index in a Mountain Array

Let’s call an array A a mountain if the following properties hold:A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < … A[i-1] < A[i] > A[i+1] > … &...

2018-08-06 19:01:49 1224

原创 What is Binary Search?

Requirement: need an ordered set of data. 大概思路: 设置一对low and high pts,在进行while(left <= right)的循环,在循环中,设置一个mid pt which equals to (low+high)/2。if([mid] = target) return mid if( [mid] < target)...

2018-08-06 18:45:09 106

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除