上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 15 下一页

2018年9月20日

Quick sort

摘要: Quick sort When solving a design problem, when should I use merge sort vs quick sort, for instance ? Idea : big class, class 1 public class QuickSort{ public int[] quickSort(int[] array){ ... 阅读全文

posted @ 2018-09-20 18:04 猪猪🐷 阅读(177) 评论(0) 推荐(0)

Rainbow sort

摘要: Rainbow sort Notes: boundary condition is tricky for me public class RainbowSort{ public int[] rainbowSort(int[] array){ if(array == null || array.length <= 1){ return array; } ... 阅读全文

posted @ 2018-09-20 18:04 猪猪&#128055; 阅读(102) 评论(0) 推荐(0)

Bucket sort

摘要: Bucket sort https://www.geeksforgeeks.org/bucket-sort-2/ Bucket sort, or bin sort, is a sorting algorithm that works by distributing the elements of an array into a number of buckets. Each bu... 阅读全文

posted @ 2018-09-20 18:03 猪猪&#128055; 阅读(74) 评论(0) 推荐(0)

Bubble sort

摘要: Bubble sort Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swapsthem... 阅读全文

posted @ 2018-09-20 18:02 猪猪&#128055; 阅读(130) 评论(0) 推荐(0)

selection sort

摘要: selection sort The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, exchanging (swapping) it with the leftmost unsorted element ... 阅读全文

posted @ 2018-09-20 18:02 猪猪&#128055; 阅读(110) 评论(0) 推荐(0)

insertion sort

摘要: insertion sort Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands. Time Complexity: O(n*2) Auxiliary Space: O(1) Boundary Cases: Insertion sort tak... 阅读全文

posted @ 2018-09-20 18:01 猪猪&#128055; 阅读(113) 评论(0) 推荐(0)

Quick select

摘要: Quick select https://www.youtube.com/watch?v=1vrdZiVmqno https://www.geeksforgeeks.org/quickselect-algorithm/ http://www.geekviewpoint.com/java/search/quickselect With unit test But this co... 阅读全文

posted @ 2018-09-20 18:00 猪猪&#128055; 阅读(317) 评论(0) 推荐(0)

2018年9月17日

857. Minimum Cost to Hire K Workers

摘要: 857. Minimum Cost to Hire K Workers There are N workers. The i-th worker has a quality[i] and a minimum wage expectation wage[i]. Now we want to hire exactly K workers to form a paid group. When hi... 阅读全文

posted @ 2018-09-17 11:59 猪猪&#128055; 阅读(250) 评论(0) 推荐(0)

2018年9月11日

longest consecutive path

摘要: Given a 2D matrix containing all positive and distinct integers in the range [1, N^2], compute the longest path containing consecutive integers in thi 阅读全文

posted @ 2018-09-11 14:47 猪猪&#128055; 阅读(91) 评论(0) 推荐(0)

2018年9月10日

Two Diff

摘要: Two Diff [1, 3, 5, 6, 7, 9], target 4. return true/false n 1 + 4 = 5 , n hashset = ( 1, 1, 3, 5, 6, 7, 9), 0 阅读全文

posted @ 2018-09-10 09:51 猪猪&#128055; 阅读(141) 评论(0) 推荐(0)

463. Island Perimeter

摘要: You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/ve 阅读全文

posted @ 2018-09-10 04:49 猪猪&#128055; 阅读(126) 评论(0) 推荐(0)

the probability of returning one element should be val of num / total vals

摘要: [1, 2, 6, 7] the probability of returning one element should be val of num / total vals 1, 2 1 1/16 2 2/16 阅读全文

posted @ 2018-09-10 04:46 猪猪&#128055; 阅读(123) 评论(0) 推荐(0)

2018年9月8日

course schedule 2 bfs indegree

摘要: bfs indegree Pretty much the same as the course schedule 1 The only diff is to return the order of the classes, which we can use a list as a container 阅读全文

posted @ 2018-09-08 10:50 猪猪&#128055; 阅读(113) 评论(0) 推荐(0)

course schedule 1 bfs indegree

摘要: Use bfs The given is [[1,0]] To take course 1 you should have finished course 0. So it is possible. So we need to convert the input into something lik 阅读全文

posted @ 2018-09-08 10:41 猪猪&#128055; 阅读(95) 评论(0) 推荐(0)

decode ways

摘要: // dfs class Solution { public int numDecodings(String s) { if(s == null || s.length() == 0) return 0; return dfs(s, 0); } private int dfs(String s, int i){ if(i ... 阅读全文

posted @ 2018-09-08 07:33 猪猪&#128055; 阅读(124) 评论(0) 推荐(0)

word break

摘要: // Time complexity : O(n^2)// Two loops are their to fill dp array. //Space complexity : O(n). Length of pp array is n+1 阅读全文

posted @ 2018-09-08 07:07 猪猪&#128055; 阅读(153) 评论(0) 推荐(0)

inorder successor bst

摘要: Given a binary search tree and a node in it, find the in-order successor of that node in the BST. Note: If the given node has no in-order successor in 阅读全文

posted @ 2018-09-08 04:35 猪猪&#128055; 阅读(119) 评论(0) 推荐(0)

inorder predecessor bst

摘要: Bst inorder successor/ predecessore With parent pointer, without parent pointer Iterative, recursive ======================================= Predecessor with a parent pointer (iterative) idea: ... 阅读全文

posted @ 2018-09-08 04:34 猪猪&#128055; 阅读(251) 评论(0) 推荐(0)

2018年8月30日

815. Bus Routes

摘要: We have a list of bus routes. Each routes[i] is a bus route that the i-th bus repeats forever. For example if routes[0] = [1, 5, 7], this means that t 阅读全文

posted @ 2018-08-30 03:28 猪猪&#128055; 阅读(144) 评论(0) 推荐(0)

2018年8月28日

791. Custom Sort String

摘要: 感觉自己的答案比较intuitive S and T are strings composed of lowercase letters. In S, no letter occurs more than once. S was sorted in some custom order previou 阅读全文

posted @ 2018-08-28 21:30 猪猪&#128055; 阅读(128) 评论(0) 推荐(0)

What is the best way to memorize or remember what you study/read?

摘要: What is the best way to memorize or remember what you study/read? Rohit Malshe, Chem Engineer, Programmer, Amazon research scientist Updated Feb 15, 2 阅读全文

posted @ 2018-08-28 21:28 猪猪&#128055; 阅读(284) 评论(0) 推荐(0)

498. Diagonal Traverse

摘要: Example: 阅读全文

posted @ 2018-08-28 21:26 猪猪&#128055; 阅读(106) 评论(0) 推荐(0)

11. Container With Most Water

摘要: The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 阅读全文

posted @ 2018-08-28 21:24 猪猪&#128055; 阅读(109) 评论(0) 推荐(0)

Swap Nodes in Pairs

摘要: Given a linked list, swap every two adjacent nodes and return its head. Example: Note: Your algorithm should use only constant extra space. You may no 阅读全文

posted @ 2018-08-28 21:23 猪猪&#128055; 阅读(72) 评论(0) 推荐(0)

399. Evaluate Division

摘要: 399. Evaluate Division Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given some queries, return th... 阅读全文

posted @ 2018-08-28 21:19 猪猪&#128055; 阅读(118) 评论(0) 推荐(0)

360. Sort Transformed Array

摘要: Solution 1 didn’t use the list is sorted, use a min heap to put all the elements in and poll them from the top until the min heap is empty Solution 2 阅读全文

posted @ 2018-08-28 20:54 猪猪&#128055; 阅读(180) 评论(0) 推荐(0)

622. Design Circular Queue

摘要: Design your implementation of the circular queue. The circular queue is a linear data structure in which the operations are performed based on FIFO (F 阅读全文

posted @ 2018-08-28 20:53 猪猪&#128055; 阅读(209) 评论(0) 推荐(0)

8. String to Integer (atoi)

摘要: Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-white 阅读全文

posted @ 2018-08-28 20:50 猪猪&#128055; 阅读(158) 评论(0) 推荐(0)

886. Possible Bipartition

摘要: Given a set of N people (numbered 1, 2, ..., N), we would like to split everyone into two groups of anysize. Each person may dislike some other people 阅读全文

posted @ 2018-08-28 20:47 猪猪&#128055; 阅读(284) 评论(0) 推荐(0)

567. Permutation in String (return true if s2 contains the permutation of s1.)

摘要: Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutati 阅读全文

posted @ 2018-08-28 20:46 猪猪&#128055; 阅读(119) 评论(0) 推荐(0)

468. Validate IP Address

摘要: Write a function to check whether an input string is a valid IPv4 address or IPv6 address or neither. IPv4 addresses are canonically represented in do 阅读全文

posted @ 2018-08-28 20:45 猪猪&#128055; 阅读(135) 评论(0) 推荐(0)

708. Insert into a Cyclic Sorted List

摘要: Given a node from a cyclic linked list which is sorted in ascending order, write a function to insert a value into the list such that it remains a cyc 阅读全文

posted @ 2018-08-28 20:44 猪猪&#128055; 阅读(300) 评论(0) 推荐(0)

99. Recover Binary Search Tree

摘要: Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. Example 1: Input: [1,3,null,null,2 阅读全文

posted @ 2018-08-28 20:43 猪猪&#128055; 阅读(134) 评论(0) 推荐(0)

681. Next Closest Time

摘要: 681. Next Closest Time Given a time represented in the format "HH:MM", form the next closest time by reusing the current digits. There is no limit on how many times a digit can be reused. You may as... 阅读全文

posted @ 2018-08-28 20:42 猪猪&#128055; 阅读(331) 评论(0) 推荐(0)

Constructor

摘要: Constructor https://www.dummies.com/programming/java/how-to-use-a-constructor-in-java/ 阅读全文

posted @ 2018-08-28 20:41 猪猪&#128055; 阅读(110) 评论(0) 推荐(0)

Integer to Roman

摘要: Idea : remove the biggest value as I can , That’s == 0 or > 0, then append the string representation while(value > 0){ if(value - values[i] >= 0){ num 阅读全文

posted @ 2018-08-28 20:40 猪猪&#128055; 阅读(108) 评论(0) 推荐(0)

13. Roman to Integer

摘要: The indexOf(String target) method searches left-to-right inside the given string for a "target" string. The indexOf() method returns the index number 阅读全文

posted @ 2018-08-28 20:39 猪猪&#128055; 阅读(106) 评论(0) 推荐(0)

862. Shortest Subarray with Sum at Least K

摘要: If there is no non-empty subarray with sum at least K, return -1. Example 1: Input: A = [1], K = 1 Output: 1 Example 2: Input: A = [1,2], K = 4 Output 阅读全文

posted @ 2018-08-28 20:19 猪猪&#128055; 阅读(347) 评论(0) 推荐(0)

437. Path Sum III

摘要: You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need t 阅读全文

posted @ 2018-08-28 20:15 猪猪&#128055; 阅读(116) 评论(0) 推荐(0)

636. Exclusive Time of Functions

摘要: Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU, find the exclusive time of these functions. Each funct 阅读全文

posted @ 2018-08-28 20:14 猪猪&#128055; 阅读(117) 评论(0) 推荐(0)

上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 15 下一页

导航