This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def titleToNumber(self, columnTitle): | |
| sum = 0 | |
| for i in range(len(columnTitle)): | |
| sum = (sum*26)+(ord(columnTitle[i])-64) | |
| return sum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public int titleToNumber(String columnTitle) { | |
| if (columnTitle == null) return -1; | |
| int sum = 0; | |
| for(int i = 0; i < columnTitle.length(); i++){ | |
| sum = ((sum*26) + ((int)columnTitle.charAt(i) - 64)); | |
| } | |
| return sum; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def majorityElement(self, nums): | |
| """ | |
| :type nums: List[int] | |
| :rtype: int | |
| """ | |
| count, res = 0,0 | |
| for num in nums: | |
| if count == 0: | |
| res = num |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution { | |
| public int majorityElement(int[] nums) { | |
| int count=0, res = 0; | |
| for (int num: nums) { | |
| if (count==0) { | |
| res = num; | |
| } | |
| if (num!=ret) { | |
| count--; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def getIntersectionNode(self, headA, headB): | |
| """ | |
| :type head1, head1: ListNode | |
| :rtype: ListNode | |
| """ | |
| # If any one of head is null i.e | |
| # no Intersection Point | |
| if headA == None or headB == None: | |
| return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Solution { | |
| public ListNode getIntersectionNode(ListNode headA, ListNode headB) { | |
| // If any one of head is null i.e | |
| // no Intersection Point | |
| if(headA == null || headB == null){ | |
| return null; | |
| } | |
| // Maintaining two pointers nodeA and nodeB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Definition for singly-linked list. | |
| # class ListNode(object): | |
| # def __init__(self, x): | |
| # self.val = x | |
| # self.next = None | |
| class Solution(object): | |
| def detectCycle(self, head): | |
| slow = fast = head | |
| # Do a loop using |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Solution { | |
| public ListNode detectCycle(ListNode head) { | |
| ListNode slow = head; | |
| ListNode fast = head; | |
| // Search it using loop | |
| // slow and fast pointers | |
| while(fast!=null && fast.next!=null){ | |
| // Move slow and fast 1 | |
| // and 2 steps ahead |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def hasCycle(self, head: Optional[ListNode]) -> bool: | |
| slow = fast = head | |
| while fast and fast.next: | |
| slow = slow.next | |
| fast = fast.next.next | |
| if slow == fast: | |
| return True | |
| return False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Solution { | |
| public boolean hasCycle(ListNode head) { | |
| ListNode slow=head; | |
| ListNode fast=head; | |
| while(fast!=null && fast.next!=null){ | |
| fast=fast.next.next; | |
| slow=slow.next; | |
| if(fast==slow){ | |
| return true; | |
| } |
NewerOlder