
算法
xj_null
到了认真的时候了。
展开
-
leetcode415
改进前的代码:public class leetcode415 { private StringBuilder res = new StringBuilder(); public String addStrings(String num1, String num2) { int length1 = num1.length(); int length2 = num2.length(); int count = 1; boole.原创 2021-02-02 23:32:11 · 135 阅读 · 0 评论 -
leetcode3
自己第一次写的代码: public int lengthOfLongestSubstring(String s) { if (s == null || s.length() == 0) { return 0; } HashMap<Character,Integer> newMap = new HashMap<>(); char[] charArr = s.toCharArray(); .原创 2021-02-02 15:37:23 · 115 阅读 · 0 评论 -
leetcode994
第一次自己写的时候的代码:import javafx.util.Pair;import java.util.*;public class leetcode994 { public int orangesRotting(int[][] grid) { int rowLength = grid.length; int colLength = grid[0].length; Queue<Pair<Integer,Integer>原创 2021-01-29 00:54:50 · 145 阅读 · 0 评论 -
为什么leetcode215的时间复杂度是O(n)而二分查找的时间复杂度是O(logn)呢?
今天刷leetcode的时候有了一个关于时间复杂度的疑问。leetcode215题是找第K大的数。里面题解的partition方法的时间复杂度是O(n),怎么得出来的呢?按照我的理解,时间复杂度就是程序运行次数的数量级。第1次遍历了整个array,代码运行次数也就是n,第2次遍历了1/2个array,代码运行次数是n/2,第3次遍历了1/4个array,代码运行次数是n/4,同理一直叠加,得到总执行次数为n + n/2 + n/4 + n/8 +...+...然而,1/2 +原创 2021-01-24 20:23:58 · 508 阅读 · 6 评论