File tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed
find-minimum-in-rotated-sorted-array
maximum-depth-of-binary-tree Expand file tree Collapse file tree 3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ class Solution {
2+ /*
3+ * 시간복잡도 O(log n)
4+ */
5+ public int findMin (int [] nums ) {
6+ int left = 0 ;
7+ int right = nums .length -1 ;
8+
9+ while (left <right ) {
10+ int mid =(right - left )/2 +left ;
11+ if (nums [right ]<nums [mid ]) {
12+ left =mid +1 ;
13+ }
14+ else right =mid ;
15+ }
16+ return nums [left ];
17+ }
18+ }
19+
Original file line number Diff line number Diff line change 1+ class Solution {
2+ /*
3+ * 시간복잡도: O(n)
4+ */
5+ public int maxDepth (TreeNode root ) {
6+ if (root ==null ) return 0 ;
7+ return 1 +Math .max (maxDepth (root .left ), maxDepth (root .right ));
8+ }
9+ }
10+
Original file line number Diff line number Diff line change 1+ class Solution {
2+ /*
3+ * 시간복잡도 O(m+n) m: list1의 길이, n: list2의 길이
4+ */
5+ public ListNode mergeTwoLists (ListNode list1 , ListNode list2 ) {
6+ if (list1 ==null ) return list2 ;
7+ if (list2 ==null ) return list1 ;
8+
9+ if (list1 .val <= list2 .val ) {
10+ list1 .next = mergeTwoLists (list1 .next , list2 );
11+ return list1 ;
12+ }
13+ else {/* */
14+ list2 .next = mergeTwoLists (list1 , list2 .next );
15+ return list2 ;
16+ }
17+ }
18+ }
19+
You can’t perform that action at this time.
0 commit comments