File tree Expand file tree Collapse file tree
lowest-common-ancestor-of-a-binary-search-tree Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /*
2+ 시간복잡도: O(log N)
3+ 공간복잡도: O(1)
4+ */
5+ class Solution {
6+ public TreeNode lowestCommonAncestor (TreeNode root , TreeNode p , TreeNode q ) {
7+ while (root != null ) {
8+ if (p .val < root .val && q .val < root .val ) {
9+ root = root .left ;
10+ } else if (p .val > root .val && q .val > root .val ) {
11+ root = root .right ;
12+ } else {
13+ return root ;
14+ }
15+ }
16+ return null ;
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * Definition of Interval:
3+ * public class Interval {
4+ * public int start, end;
5+ * public Interval(int start, int end) {
6+ * this.start = start;
7+ * this.end = end;
8+ * }
9+ * }
10+ */
11+
12+ class Solution {
13+ public boolean canAttendMeetings (List <Interval > intervals ) {
14+ intervals .sort ((a , b ) -> {
15+ if (a .start != b .start ) return Integer .compare (a .start , b .start );
16+ return Integer .compare (a .end , b .end );
17+ });
18+
19+ for (int i = 1 ; i < intervals .size (); i ++) {
20+ if (intervals .get (i -1 ).end > intervals .get (i ).start ) {
21+ return false ;
22+ }
23+ }
24+ return true ;
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments